ZQuest Classic Coverage Report


Directory: src/
File: src/zc/ffscript.cpp
Date: 2025-08-14 17:56:01
Exec Total Coverage
Lines: 6816 20771 32.8%
Functions: 460 980 46.9%
Branches: 3848 16402 23.5%

Line Branch Exec Source
1 #include <cstdint>
2 #include <deque>
3 #include <memory>
4 #include <string>
5 #include <sstream>
6 #include <math.h>
7 #include <cstdio>
8 #include <algorithm>
9 #include <ranges>
10 //
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <fstream>
16 #include <filesystem>
17 #include <fmt/format.h>
18 #include <fmt/ranges.h>
19 //
20
21 #include "base/check.h"
22 #include "base/expected.h"
23 #include "base/handles.h"
24 #include "base/general.h"
25 #include "base/mapscr.h"
26 #include "base/qrs.h"
27 #include "base/dmap.h"
28 #include "base/msgstr.h"
29 #include "base/packfile.h"
30 #include "base/misctypes.h"
31 #include "base/initdata.h"
32 #include "base/version.h"
33 #include "new_subscr.h"
34 #include "zc/maps.h"
35 #include "zasm/serialize.h"
36 #include "zasm/table.h"
37 #include "zc/replay.h"
38 #include "zc/scripting/arrays.h"
39 #include "zc/scripting/script_object.h"
40 #include "zc/scripting/types.h"
41 #include "zc/scripting/types/websocket.h"
42 #include "zc/zasm_optimize.h"
43 #include "zc/zasm_utils.h"
44 #include "zc/zc_ffc.h"
45 #include "zc/zc_sys.h"
46 #include "zc/jit.h"
47 #include "zc/script_debug.h"
48 #include "base/zc_alleg.h"
49 #include "base/zc_math.h"
50 #include "base/zc_array.h"
51 #include "zc/ffscript.h"
52 #include "zc/render.h"
53 #include "zc/zc_subscr.h"
54 #include <time.h>
55 #include "zc/script_drawing.h"
56 #include "base/util.h"
57 #include "zc/ending.h"
58 #include "zc/combos.h"
59 #include "drawing.h"
60 #include "base/colors.h"
61 #include "pal.h"
62 #include "zinfo.h"
63 #include "subscr.h"
64 #include "zc_list_data.h"
65 #include "music_playback.h"
66 #include "iter.h"
67 #include <sstream>
68
69 #include "zc/zelda.h"
70 #include "particles.h"
71 #include "zc/hero.h"
72 #include "zc/guys.h"
73 #include "gamedata.h"
74 #include "zc/zc_init.h"
75 #include "base/zsys.h"
76 #include "base/misctypes.h"
77 #include "zc/title.h"
78 #include "zscriptversion.h"
79
80 #include "pal.h"
81 #include "base/zdefs.h"
82 #include "zc/rendertarget.h"
83
84 #include "hero_tiles.h"
85 #include "base/qst.h"
86
87 using namespace util;
88
89 #ifdef _WIN32
90 #define SCRIPT_FILE_MODE (_S_IREAD | _S_IWRITE)
91 #else
92 #include <fcntl.h>
93 #include <unistd.h>
94 #include <iostream>
95 #define SCRIPT_FILE_MODE (S_ISVTX | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
96 #endif
97
98 //Define this register, so it can be treated specially
99 #define NUL 5
100 #define MAX_ZC_ARRAY_SIZE 214748
101
102 using namespace util;
103 using std::ostringstream;
104
105 static ASM_DEFINE current_zasm_command;
106 static uint32_t current_zasm_register;
107 // If set, the next call to scripting_log_error_with_context will use this string in addition to whatever
108 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
109 std::string current_zasm_extra_context;
110 // If set, the next call to scripting_log_error_with_context will use this string instead of whatever
111 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
112 std::string current_zasm_context;
113
114 2031899 void scripting_log_error_with_context(std::string text)
115 {
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2031899 times.
2031899 if (current_zasm_context.empty())
117 {
118 2031899 std::vector<const char*> context;
119
120
1/2
✓ Branch 0 taken 2031899 times.
✗ Branch 1 not taken.
2031899 const char* register_string = scripting_get_zasm_register_context_string(current_zasm_register);
121
2/2
✓ Branch 0 taken 1005624 times.
✓ Branch 1 taken 1026275 times.
2031899 if (register_string)
122
1/2
✓ Branch 0 taken 1005624 times.
✗ Branch 1 not taken.
1005624 context.push_back(register_string);
123
124
1/2
✓ Branch 0 taken 2031899 times.
✗ Branch 1 not taken.
2031899 const char* command_string = scripting_get_zasm_command_context_string(current_zasm_command);
125
2/2
✓ Branch 0 taken 387191 times.
✓ Branch 1 taken 1644708 times.
2031899 if (command_string)
126
1/2
✓ Branch 0 taken 387191 times.
✗ Branch 1 not taken.
387191 context.push_back(command_string);
127
128
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2031895 times.
2031899 if (!current_zasm_extra_context.empty())
129
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 context.push_back(current_zasm_extra_context.c_str());
130
131
2/2
✓ Branch 0 taken 1390953 times.
✓ Branch 1 taken 640946 times.
2031899 if (context.size())
132
3/6
✓ Branch 0 taken 1390953 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1390953 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1390953 times.
✗ Branch 5 not taken.
1390953 current_zasm_context = fmt::format("{}", fmt::join(context, ", "));
133 else
134 {
135
1/2
✓ Branch 0 taken 640946 times.
✗ Branch 1 not taken.
640946 Z_scripterrlog("%s\n", text.c_str());
136 640946 return;
137 }
138
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 640946 times.
✓ Branch 2 taken 1390953 times.
2031899 }
139
140 1390953 Z_scripterrlog("%s | %s\n", current_zasm_context.c_str(), text.c_str());
141 1390953 current_zasm_context = "";
142 1390953 current_zasm_extra_context = "";
143 2031899 }
144
145 // (type, index) => ScriptEngineData
146 412 std::map<std::pair<ScriptType, int>, ScriptEngineData> scriptEngineDatas;
147
148 extern byte use_dwm_flush;
149 uint8_t using_SRAM = 0;
150
151 int32_t hangcount = 0;
152 bool can_neg_array = true;
153
154 extern byte monochrome_console;
155
156 412 static std::map<script_id, ScriptDebugHandle> script_debug_handles;
157 ScriptDebugHandle* runtime_script_debug_handle;
158 int32_t jitted_uncompiled_command_count;
159
160 412 CScriptDrawingCommands scriptdraws;
161 412 FFScript FFCore;
162
163 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file);
164
165 static UserDataContainer<script_array, 1000000> script_arrays = {script_object_type::array, "array"};
166 static UserDataContainer<user_dir, MAX_USER_DIRS> user_dirs = {script_object_type::dir, "directory"};
167 static UserDataContainer<user_file, MAX_USER_FILES> user_files = {script_object_type::file, "file"};
168 static UserDataContainer<user_paldata, MAX_USER_PALDATAS> user_paldatas = {script_object_type::paldata, "paldata"};
169 static UserDataContainer<user_rng, MAX_USER_RNGS> user_rngs = {script_object_type::rng, "rng"};
170 static UserDataContainer<user_stack, MAX_USER_STACKS> user_stacks = {script_object_type::stack, "stack"};
171 static UserDataContainer<user_bitmap, MAX_USER_BITMAPS> user_bitmaps = {script_object_type::bitmap, "bitmap"};
172
173 210 script_array* create_script_array()
174 {
175 210 return script_arrays.create();
176 }
177
178 132 void register_existing_script_array(script_array* array)
179 {
180 132 script_arrays.register_existing(array);
181 132 }
182
183 61 std::vector<script_array*> get_script_arrays()
184 {
185 61 std::vector<script_array*> result;
186
3/4
✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 146 times.
207 for (auto id : script_object_ids_by_type[script_arrays.type])
187 {
188
2/4
✓ Branch 0 taken 146 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146 times.
✗ Branch 3 not taken.
146 result.push_back(&script_arrays[id]);
189 }
190 61 return result;
191
1/2
✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
61 }
192
193 26 static script_array* find_or_create_internal_script_array(script_array::internal_array_id internal_id)
194 {
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (!zasm_array_supports(internal_id.zasm_var))
196 {
197 scripting_log_error_with_context("Invalid internal array id: {}", internal_id.zasm_var);
198 return nullptr;
199 }
200
201
2/2
✓ Branch 0 taken 830 times.
✓ Branch 1 taken 10 times.
840 for (auto id : script_object_ids_by_type[script_arrays.type])
202 {
203 830 auto object = static_cast<script_array*>(get_script_object_checked(id));
204
5/6
✓ Branch 0 taken 830 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 796 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 16 times.
830 if (!object->internal_expired && object->internal_id.has_value() && object->internal_id.value() == internal_id)
205 16 return object;
206 }
207
208 10 auto array = script_arrays.create();
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (array)
210 {
211 10 array->arr.setValid(true);
212 10 array->internal_id = internal_id;
213 10 }
214 10 return array;
215 26 }
216
217 2313535 static void expire_internal_script_arrays(ScriptType scriptType, int ref)
218 {
219
2/2
✓ Branch 0 taken 957394 times.
✓ Branch 1 taken 1356141 times.
2313535 if (!ZScriptVersion::gc_arrays())
220 1356141 return;
221
222 // Expire internal arrays referring to this script object.
223
2/2
✓ Branch 0 taken 957394 times.
✓ Branch 1 taken 908126 times.
1865520 for (auto& script_object : script_objects | std::views::values)
224 {
225
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 907373 times.
908126 if (script_object->type != script_object_type::array)
226 753 continue;
227
228 907373 auto array = static_cast<script_array*>(script_object.get());
229
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 907365 times.
907373 if (!array->internal_id.has_value())
230 907365 continue;
231
232
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if (array->internal_id->matches(scriptType, ref))
233 2 array->internal_expired = true;
234 }
235 2313535 }
236
237 35854 static void expire_internal_script_arrays(ScriptType scriptType)
238 {
239
2/2
✓ Branch 0 taken 17454 times.
✓ Branch 1 taken 18400 times.
35854 if (!ZScriptVersion::gc_arrays())
240 18400 return;
241
242 // Expire internal arrays referring to this script object.
243
2/2
✓ Branch 0 taken 17454 times.
✓ Branch 1 taken 13682 times.
31136 for (auto& script_object : script_objects | std::views::values)
244 {
245
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 13622 times.
13682 if (script_object->type != script_object_type::array)
246 60 continue;
247
248 13622 auto array = static_cast<script_array*>(script_object.get());
249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13622 times.
13622 if (!array->internal_id.has_value())
250 13622 continue;
251
252 if (array->internal_id->matches(scriptType))
253 array->internal_expired = true;
254 }
255 35854 }
256
257 65503598 script_array* checkArray(uint32_t id, bool skipError)
258 {
259 65503598 return script_arrays.check(id, skipError);
260 }
261
262 16248612 void script_bitmaps::update()
263 {
264 16248612 auto ids = script_object_ids_by_type[user_bitmaps.type];
265
2/2
✓ Branch 0 taken 35976099 times.
✓ Branch 1 taken 16248612 times.
52224711 for (auto id : ids)
266 {
267
1/2
✓ Branch 0 taken 35976099 times.
✗ Branch 1 not taken.
35976099 auto& bitmap = user_bitmaps[id];
268
3/4
✓ Branch 0 taken 35976099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3656 times.
✓ Branch 3 taken 35972443 times.
35976099 if (bitmap.is_freeing())
269 {
270
1/2
✓ Branch 0 taken 3656 times.
✗ Branch 1 not taken.
3656 bitmap.mark_can_del();
271
1/2
✓ Branch 0 taken 3656 times.
✗ Branch 1 not taken.
3656 delete_script_object(id);
272 3656 }
273 }
274 16248612 }
275
276 320322 user_bitmap& script_bitmaps::get(int32_t id)
277 {
278
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 320316 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
320322 static user_bitmap fake;
279
280 320322 current_zasm_context = "script drawing";
281
1/2
✓ Branch 0 taken 320322 times.
✗ Branch 1 not taken.
320322 if (auto bitmap = user_bitmaps.check(id))
282 {
283 320322 current_zasm_context = "";
284 320322 return *bitmap;
285 }
286
287 return fake;
288 320322 }
289
290 script_bitmaps scb;
291 412 user_rng nulrng;
292 412 zc_randgen script_rnggens[MAX_USER_RNGS];
293
294 FONT *get_zc_font(int index);
295
296 int32_t combopos_modified = -1;
297 static std::vector<word> combo_id_cache;
298
299 void user_dir::setPath(const char* buf)
300 {
301 if(!list)
302 {
303 list = (FLIST *) calloc(1, sizeof(FLIST));
304 }
305 filepath = std::string(buf) + "/";
306 regulate_path(filepath);
307 list->load(filepath.c_str());
308 }
309
310 int32_t CScriptDrawingCommands::GetCount()
311 {
312 al_trace("current number of draws is: %d\n", count);
313 return count;
314 }
315
316 // Decodes a `mapref` (reference number) for a temporary screen.
317 //
318 // A mapref can refer to:
319 //
320 // - the canonical mapscr data, loaded via `Game->LoadMapData(int map, int screen)`
321 // - a temporary mapscr, loaded via `Game->LoadTempScreen(int layer, int? screen)`
322 // - a temporary mapscr, loaded via `Game->LoadScrollingScreen(int layer, int? screen)`
323 //
324 // The canonical maprefs are >=0, and temporary ones are all negative.
325 //
326 // If temporary, and loaded without specifiying a screen index, we allow combo array variables (like
327 // `ComboX[pos]`) to address any rpos in the region. Otherwise, only positions in the exact screen
328 // referenced by `mapref` can be used (0-175). See ResolveMapdataPos.
329 88395866 mapdata decode_mapdata_ref(int ref)
330 {
331
2/2
✓ Branch 0 taken 19036716 times.
✓ Branch 1 taken 69359150 times.
88395866 if (ref >= 0)
332 {
333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19036716 times.
19036716 if (ref >= TheMaps.size())
334 return mapdata{};
335
336 19036716 int screen = ref % MAPSCRS;
337 19036716 return mapdata{mapdata_type::CanonicalScreen, &TheMaps[ref], screen, 0};
338 }
339
340 // Negative values are for temporary screens.
341
342 69359150 ref = -(ref + 1);
343 69359150 bool is_scrolling = ref & 1;
344 69359150 bool is_region = ref & 2;
345 69359150 int screen = (ref & 0x0000FF00) >> 8;
346 69359150 int layer = (ref & 0x00FF0000) >> 16;
347
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_region)
349 {
350
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_scrolling)
351 screen = scrolling_region.origin_screen;
352 else
353 69359150 screen = cur_screen;
354 69359150 }
355
356 69359150 mapscr* scr = nullptr;
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_scrolling)
358 {
359 int index = screen * 7 + layer;
360 if (index >= 0 && index < FFCore.ScrollingScreensAll.size())
361 scr = FFCore.ScrollingScreensAll[index];
362 }
363 else
364 {
365
3/6
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69359150 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 69359150 times.
69359150 if (layer >= 0 && layer <= 6 && is_in_current_region(screen))
366 69359150 scr = get_scr_layer(screen, layer);
367 }
368
369
1/2
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
69359150 if (!scr)
370 return mapdata{};
371
372 69359150 auto type = mapdata_type::None;
373
2/4
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69359150 times.
✗ Branch 3 not taken.
69359150 if (is_region && is_scrolling)
374 type = mapdata_type::TemporaryScrollingRegion;
375
2/4
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 69359150 times.
69359150 else if (is_region && !is_scrolling)
376 69359150 type = mapdata_type::TemporaryCurrentRegion;
377 else if (!is_region && is_scrolling)
378 type = mapdata_type::TemporaryScrollingScreen;
379 else if (!is_region && !is_scrolling)
380 type = mapdata_type::TemporaryCurrentScreen;
381
382 69359150 return mapdata{type, scr, screen, layer};
383 88395866 }
384
385 3387223 static int create_mapdata_temp_ref(mapdata_type type, int screen, int layer)
386 {
387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3387223 times.
3387223 bool is_scrolling = type == mapdata_type::TemporaryScrollingScreen || type == mapdata_type::TemporaryScrollingRegion;
388
2/2
✓ Branch 0 taken 177544 times.
✓ Branch 1 taken 3209679 times.
3387223 bool is_region = type == mapdata_type::TemporaryScrollingRegion || type == mapdata_type::TemporaryCurrentRegion;
389
390 3387223 int ref = 0;
391 3387223 ref |= is_scrolling ? 1 : 0;
392 3387223 ref |= is_region ? 2 : 0;
393
1/2
✓ Branch 0 taken 3387223 times.
✗ Branch 1 not taken.
3387223 if (!is_region)
394 ref |= ((screen & 0xFF) << 8);
395 3387223 ref |= ((layer & 0xFF) << 16);
396 3387223 return -ref-1;
397 }
398
399 mapscr* GetScrollingMapscr(int layer, int x, int y)
400 {
401 if (!screenscrolling)
402 return nullptr;
403
404 int screen = scrolling_region.origin_screen + map_scr_xy_to_index(x / 256, y / 176);
405 mapscr* m = FFCore.ScrollingScreensAll[screen * 7 + layer];
406 if (!m || !m->is_valid())
407 return nullptr;
408
409 return m;
410 }
411
412 9 int32_t getMap(int32_t ref)
413 {
414
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
9 switch(ref)
415 {
416 case MAPSCR_TEMP0:
417 return cur_map+1;
418 case MAPSCR_TEMP1:
419 return origin_scr->layermap[0];
420 case MAPSCR_TEMP2:
421 return origin_scr->layermap[1];
422 case MAPSCR_TEMP3:
423 return origin_scr->layermap[2];
424 case MAPSCR_TEMP4:
425 return origin_scr->layermap[3];
426 case MAPSCR_TEMP5:
427 return origin_scr->layermap[4];
428 case MAPSCR_TEMP6:
429 return origin_scr->layermap[5];
430 case MAPSCR_SCROLL0:
431 return scrolling_map+1;
432 case MAPSCR_SCROLL1:
433 return special_warp_return_scr->layermap[0];
434 case MAPSCR_SCROLL2:
435 return special_warp_return_scr->layermap[1];
436 case MAPSCR_SCROLL3:
437 return special_warp_return_scr->layermap[2];
438 case MAPSCR_SCROLL4:
439 return special_warp_return_scr->layermap[3];
440 case MAPSCR_SCROLL5:
441 return special_warp_return_scr->layermap[4];
442 case MAPSCR_SCROLL6:
443 return special_warp_return_scr->layermap[5];
444 default:
445 9 return (ref / MAPSCRS + 1);
446 }
447 9 }
448 21 int32_t getScreen(int32_t ref)
449 {
450
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
21 switch(ref)
451 {
452 case MAPSCR_TEMP0:
453 return cur_screen;
454 case MAPSCR_TEMP1:
455 return origin_scr->layerscreen[0];
456 case MAPSCR_TEMP2:
457 return origin_scr->layerscreen[1];
458 case MAPSCR_TEMP3:
459 return origin_scr->layerscreen[2];
460 case MAPSCR_TEMP4:
461 return origin_scr->layerscreen[3];
462 case MAPSCR_TEMP5:
463 return origin_scr->layerscreen[4];
464 case MAPSCR_TEMP6:
465 return origin_scr->layerscreen[5];
466 case MAPSCR_SCROLL0:
467 return scrolling_hero_screen;
468 case MAPSCR_SCROLL1:
469 return special_warp_return_scr->layerscreen[0];
470 case MAPSCR_SCROLL2:
471 return special_warp_return_scr->layerscreen[1];
472 case MAPSCR_SCROLL3:
473 return special_warp_return_scr->layerscreen[2];
474 case MAPSCR_SCROLL4:
475 return special_warp_return_scr->layerscreen[3];
476 case MAPSCR_SCROLL5:
477 return special_warp_return_scr->layerscreen[4];
478 case MAPSCR_SCROLL6:
479 return special_warp_return_scr->layerscreen[5];
480 default:
481 21 return (ref % MAPSCRS);
482 }
483 21 }
484
485 654492848 static ffcdata* get_ffc(ffc_id_t ffc_id)
486 {
487 654492848 return &get_scr_for_region_index_offset(ffc_id / MAXFFCS)->getFFC(ffc_id % MAXFFCS);
488 }
489
490 94642 dword get_subref(int sub, byte ty, byte pg, word ind)
491 {
492 byte s;
493
2/2
✓ Branch 0 taken 79480 times.
✓ Branch 1 taken 15162 times.
94642 if(sub == -1) //special; load current
494 {
495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15162 times.
15162 if (new_sub_indexes[ty] < 0) return 0;
496 15162 s = new_sub_indexes[ty];
497 15162 }
498
1/2
✓ Branch 0 taken 79480 times.
✗ Branch 1 not taken.
79480 else if(unsigned(sub) < 256)
499 79480 s = sub;
500 else return 0;
501 94642 ++ty; //type is offset by 1
502 94642 return (s<<24)|(pg<<16)|((ty&0x7)<<13)|(ind&0x1FFF);
503 94642 }
504 414110 std::tuple<byte,int8_t,byte,word> from_subref(dword ref)
505 {
506 414110 byte type = (ref>>13)&0x07;
507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414110 times.
414110 if(!type)
508 return { 0, -1, 0, 0 };
509
510 414110 byte sub = (ref>>24)&0xFF;
511 414110 byte pg = (ref>>16)&0xFF;
512 414110 word ind = (ref)&0x1FFF;
513 414110 return { sub, type-1, pg, ind };
514 414110 }
515
516 334633 std::tuple<ZCSubscreen*,SubscrPage*,SubscrWidget*,byte> load_subscreen_ref(dword ref)
517 {
518 1673165 auto [sub,ty,pg,ind] = from_subref(ref);
519 334633 ZCSubscreen* sbscr = nullptr;
520 334633 SubscrPage* sbpg = nullptr;
521 334633 SubscrWidget* sbwidg = nullptr;
522
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
334633 switch(ty)
523 {
524 case sstACTIVE:
525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(sub < subscreens_active.size())
526 334633 sbscr = &subscreens_active[sub];
527 334633 break;
528 case sstPASSIVE:
529 if(sub < subscreens_passive.size())
530 sbscr = &subscreens_passive[sub];
531 break;
532 case sstOVERLAY:
533 if(sub < subscreens_overlay.size())
534 sbscr = &subscreens_overlay[sub];
535 break;
536 }
537
1/2
✓ Branch 0 taken 334633 times.
✗ Branch 1 not taken.
334633 if(sbscr)
538 {
539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(pg < sbscr->pages.size())
540 669266 sbpg = &sbscr->pages[pg];
541 334633 }
542 else return { nullptr, nullptr, nullptr, -1 }; //no subscreen
543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(sbpg)
544 {
545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(ind < sbpg->size())
546 669266 sbwidg = sbpg->at(ind);
547 334633 }
548 334633 return { sbscr, sbpg, sbwidg, ty };
549 334633 }
550 174863 std::pair<ZCSubscreen*,byte> load_subdata(dword ref)
551 {
552 174863 auto [sub,_pg,_widg,ty] = load_subscreen_ref(ref);
553 174863 return { sub, ty };
554 }
555 56028 std::pair<SubscrPage*,byte> load_subpage(dword ref)
556 {
557 56028 auto [_sub,pg,_widg,ty] = load_subscreen_ref(ref);
558 56028 return { pg, ty };
559 }
560 103742 std::pair<SubscrWidget*,byte> load_subwidg(dword ref)
561 {
562 103742 auto [_sub,_pg,widg,ty] = load_subscreen_ref(ref);
563 103742 return { widg, ty };
564 }
565
566 #include "zconsole/ConsoleLogger.h"
567
568 //no ifdef here
569 extern CConsoleLoggerEx zscript_coloured_console;
570
571 bool FFScript::isNumber(char chr)
572 {
573 if ( chr >= '0' )
574 {
575 if ( chr <= '9' ) return true;
576 }
577 return false;
578 }
579
580 int32_t FFScript::ilen(char *p)
581 {
582 int32_t ret = 0; int32_t pos = 0;
583 if(p[pos] == '-')
584 ret++;
585 for(; FFCore.isNumber(p[pos + ret]); ++ret);
586 return ret;
587 }
588
589 int32_t FFScript::atox(char *ip_str)
590 {
591 char tmp[2]={'2','\0'};
592 int32_t op_val=0, i=0, ip_len = strlen(ip_str);
593
594 if(strncmp(ip_str, "0x", 2) == 0)
595 {
596 ip_str +=2;
597 ip_len -=2;
598 }
599
600 for(i=0;i<ip_len;i++)
601 {
602 op_val *= 0x10;
603 switch(ip_str[i])
604 {
605 case 'a':
606 op_val += 0xa;
607 break;
608 case 'b':
609 op_val += 0xb;
610 break;
611 case 'c':
612 op_val += 0xc;
613 break;
614 case 'd':
615 op_val += 0xd;
616 break;
617 case 'e':
618 op_val += 0xe;
619 break;
620 case 'f':
621 op_val += 0xf;
622 break;
623 case '0':
624 case '1':
625 case '2':
626 case '3':
627 case '4':
628 case '5':
629 case '6':
630 case '7':
631 case '8':
632 case '9':
633 tmp[0] = ip_str[i];
634 op_val += atoi(tmp);
635 break;
636 default :
637 op_val += 0x0;
638 break;
639 }
640 }
641 return op_val;
642 }
643
644 char runningItemScripts[256] = {0};
645
646 //item *FFCore.temp_ff_item = NULL;
647 //enemy *FFCore.temp_ff_enemy = NULL;
648 //weapon *FFCore.temp_ff_lweapon = NULL;
649 //weapon *FFCore.temp_ff_eweapon = NULL;
650
651 extern int32_t directItemA;
652 extern int32_t directItemB;
653 extern int32_t directItemX;
654 extern int32_t directItemY;
655
656
657 #ifdef _MSC_VER
658 #pragma warning ( disable : 4800 ) //int32_t to bool town. population: lots.
659 #endif
660
661 //! New datatype vars for 2.54:
662
663 //spritedata sp->member
664
665
666 using std::string;
667
668 extern char *guy_string[];
669 extern int32_t skipcont;
670
671 PALETTE tempgreypal; //Palettes go here. This is used for Greyscale() / Monochrome()
672 PALETTE userPALETTE[256]; //Palettes go here. This is used for Greyscale() / Monochrome()
673 PALETTE tempblackpal; //Used for storing the palette while fading to black
674
675 byte FF_hero_action; //This way, we can make safe replicas of internal Hero actions to be set by script.
676
677 int32_t FF_screenbounds[4]; //edges of the screen, left, right, top, bottom used for where to scroll.
678 int32_t FF_screen_dimensions[4]; //height, width, displaywidth, displayheight
679 int32_t FF_subscreen_dimensions[4];
680 int32_t FF_eweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic eweapon removal.
681 int32_t FF_lweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic lweapon removal.
682 int32_t FF_clocks[FFSCRIPTCLASS_CLOCKS]; //Will be used for Heroaction, anims, and so forth
683 byte ScriptDrawingRules[SCRIPT_DRAWING_RULES];
684 int32_t FF_UserMidis[NUM_USER_MIDI_OVERRIDES]; //MIDIs to use for Game Over, and similar to override system defaults.
685
686 int32_t legacy_get_int_arr(const int32_t ptr, int32_t indx);
687 void legacy_set_int_arr(const int32_t ptr, int32_t indx, int32_t val);
688 int32_t legacy_sz_int_arr(const int32_t ptr);
689
690 //We gain some speed by not passing as arguments
691 int32_t sarg1;
692 int32_t sarg2;
693 int32_t sarg3;
694 vector<int32_t> *sargvec;
695 string *sargstr;
696 refInfo *ri;
697 script_data *curscript;
698 int32_t(*stack)[MAX_STACK_SIZE];
699 bounded_vec<word, int32_t>* ret_stack;
700 vector<int32_t> zs_vargs;
701 ScriptType curScriptType;
702 word curScriptNum;
703 int32_t curScriptIndex;
704 bool script_funcrun;
705 string* destructstr;
706 size_t gen_frozen_index;
707
708 static vector<ScriptType> curScriptType_cache;
709 static vector<int32_t> curScriptNum_cache;
710 static vector<int32_t> curScriptIndex_cache;
711 static vector<int32_t> sarg1cache;
712 static vector<int32_t> sarg2cache;
713 static vector<int32_t> sarg3cache;
714 static vector<vector<int32_t>*> sargvec_cache;
715 static vector<string*> sargstr_cache;
716 static vector<refInfo*> ricache;
717 static vector<script_data*> sdcache;
718 static vector<int32_t(*)[MAX_STACK_SIZE]> stackcache;
719 static vector<bounded_vec<word, int32_t>*> ret_stack_cache;
720 820 void push_ri()
721 {
722 820 sarg1cache.push_back(sarg1);
723 820 sarg2cache.push_back(sarg2);
724 820 sarg3cache.push_back(sarg3);
725 820 curScriptType_cache.push_back(curScriptType);
726 820 curScriptNum_cache.push_back(curScriptNum);
727 820 curScriptIndex_cache.push_back(curScriptIndex);
728 820 sargvec_cache.push_back(sargvec);
729 820 sargstr_cache.push_back(sargstr);
730 820 ricache.push_back(ri);
731 820 sdcache.push_back(curscript);
732 820 stackcache.push_back(stack);
733 820 ret_stack_cache.push_back(ret_stack);
734 820 }
735 820 void pop_ri()
736 {
737 820 sarg1 = sarg1cache.back(); sarg1cache.pop_back();
738 820 sarg2 = sarg2cache.back(); sarg2cache.pop_back();
739 820 sarg3 = sarg3cache.back(); sarg3cache.pop_back();
740 820 curScriptType = curScriptType_cache.back(); curScriptType_cache.pop_back();
741 820 curScriptNum = curScriptNum_cache.back(); curScriptNum_cache.pop_back();
742 820 curScriptIndex = curScriptIndex_cache.back(); curScriptIndex_cache.pop_back();
743 820 sargvec = sargvec_cache.back(); sargvec_cache.pop_back();
744 820 sargstr = sargstr_cache.back(); sargstr_cache.pop_back();
745 820 ri = ricache.back(); ricache.pop_back();
746 820 curscript = sdcache.back(); sdcache.pop_back();
747 820 stack = stackcache.back(); stackcache.pop_back();
748 820 ret_stack = ret_stack_cache.back(); ret_stack_cache.pop_back();
749 820 }
750
751 //START HELPER FUNCTIONS
752 ///-------------------------------------//
753 // Helper Functions //
754 ///-------------------------------------//
755
756 2 static void log_stack_overflow_error()
757 {
758
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 scripting_log_error_with_context("Stack overflow!");
759 2 }
760
761 2 static void log_call_limit_error()
762 {
763 2 scripting_log_error_with_context("Function call limit reached! Too much recursion. Max nested function calls is {}", MAX_CALL_FRAMES);
764 2 }
765
766 1534523714 void SH::write_stack(const uint32_t sp, const int32_t value)
767 {
768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1534523714 times.
1534523714 if (sp >= MAX_STACK_SIZE)
769 {
770 log_stack_overflow_error();
771 ri->overflow = true;
772 return;
773 }
774
775 1534523714 (*stack)[sp] = value;
776 1534523714 }
777
778 2897852142 int32_t SH::read_stack(const uint32_t sp)
779 {
780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2897852142 times.
2897852142 if (sp >= MAX_STACK_SIZE)
781 {
782 log_stack_overflow_error();
783 ri->overflow = true;
784 return -10000;
785 }
786
787 2897852142 return (*stack)[sp];
788 2897852142 }
789
790 ///----------------------------//
791 // Misc. //
792 ///----------------------------//
793
794 byte flagpos;
795 int32_t flagval;
796 21469831 void clear_ornextflag()
797 {
798 21469831 flagpos = 0;
799 21469831 flagval = 0;
800 21469831 }
801 145861533 void ornextflag(bool flag)
802 {
803
2/2
✓ Branch 0 taken 143700973 times.
✓ Branch 1 taken 2160560 times.
145861533 if(flag) flagval |= 1<<flagpos;
804 145861533 ++flagpos;
805 145861533 }
806
807 11161012 int32_t get_screenflags(mapscr *m, int32_t flagset)
808 {
809 11161012 clear_ornextflag();
810
811
5/11
✓ Branch 0 taken 4807572 times.
✓ Branch 1 taken 6263768 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 52 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 89609 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
11161012 switch(flagset)
812 {
813 case 0: // Room Type
814 4807572 ornextflag(m->flags6&1);
815 4807572 ornextflag(m->flags6&2);
816 4807572 ornextflag(m->flags7&8);
817 4807572 break;
818
819 case 1: // View
820 6263768 ornextflag(m->flags3&8);
821 6263768 ornextflag(m->flags7&16);
822 6263768 ornextflag(m->flags3&16);
823 6263768 ornextflag(m->flags3&64);
824 6263768 ornextflag(m->flags7&2);
825 6263768 ornextflag(m->flags7&1);
826 6263768 ornextflag(m->flags&fDARK);
827 6263768 ornextflag(m->flags9&fDARK_DITHER);
828 6263768 ornextflag(m->flags9&fDARK_TRANS);
829 6263768 break;
830
831 case 2: // Secrets
832 11 ornextflag(m->flags&1);
833 11 ornextflag(m->flags5&16);
834 11 ornextflag(m->flags6&4);
835 11 ornextflag(m->flags6&32);
836 11 break;
837
838 case 3: // Warp
839 ornextflag(m->flags5&4);
840 ornextflag(m->flags5&8);
841 ornextflag(m->flags&64);
842 ornextflag(m->flags8&64);
843 ornextflag(m->flags3&32);
844 ornextflag(m->flags9&fDISABLE_MIRROR);
845 ornextflag(m->flags10&fMAZE_CAN_GET_LOST);
846 ornextflag(m->flags10&fMAZE_LOOPY);
847 break;
848
849 case 4: // Item
850 52 ornextflag(m->flags3&1);
851 52 ornextflag(m->flags7&4);
852 52 ornextflag(m->flags8&0x40);
853 52 ornextflag(m->flags8&0x80);
854 52 ornextflag(m->flags9&0x01);
855 52 ornextflag(m->flags9&0x02);
856 52 ornextflag(m->flags9&fBELOWRETURN);
857 52 break;
858
859 case 5: // Combo
860 ornextflag((m->flags2>>4)&2);
861 ornextflag(m->flags3&2);
862 ornextflag(m->flags5&2);
863 ornextflag(m->flags6&64);
864 break;
865
866 case 6: // Save
867 ornextflag(m->flags4&64);
868 ornextflag(m->flags4&128);
869 ornextflag(m->flags6&8);
870 ornextflag(m->flags6&16);
871 break;
872
873 case 7: // FFC
874 ornextflag(m->flags6&128);
875 ornextflag(m->flags5&128);
876 break;
877
878 case 8: // Whistle
879 ornextflag(m->flags&16);
880 ornextflag(m->flags7&64);
881 ornextflag(m->flags7&128);
882 break;
883
884 case 9: // Misc
885 89609 ornextflag(m->flags&32);
886 89609 ornextflag(m->flags5&64);
887 89609 flagval |= m->flags8<<2;
888 89609 break;
889 }
890
891 11161012 return flagval;
892 }
893
894 4473523 int32_t get_screeneflags(mapscr *m, int32_t flagset)
895 {
896 4473523 clear_ornextflag();
897
898
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4473221 times.
✓ Branch 3 taken 302 times.
4473523 switch(flagset)
899 {
900 case 0:
901 flagval |= m->flags11&0x1F;
902 break;
903
904 case 1:
905 4473221 ornextflag(m->flags11&32);
906 4473221 ornextflag(m->flags11&64);
907 4473221 ornextflag(m->flags3&4);
908 4473221 ornextflag(m->flags11&128);
909 4473221 ornextflag((m->flags2>>4)&4);
910 4473221 break;
911
912 case 2:
913 302 ornextflag(m->flags3&128);
914 302 ornextflag(m->flags&2);
915 302 ornextflag((m->flags2>>4)&8);
916 302 ornextflag(m->flags4&16);
917 302 ornextflag(m->flags9&fENEMY_WAVES);
918 302 break;
919 }
920
921 4473523 return flagval;
922 }
923
924 int32_t get_mi(int32_t ref)
925 {
926 auto result = decode_mapdata_ref(ref);
927 if (result.canonical())
928 {
929 if (result.screen >= MAPSCRSNORMAL) return -1;
930 return mapind(result.scr->map, result.screen);
931 }
932 else if (result.current())
933 {
934 if (result.screen >= MAPSCRSNORMAL) return -1;
935 return mapind(cur_map, result.screen);
936 }
937 else if (result.scrolling())
938 {
939 if (result.screen >= MAPSCRSNORMAL) return -1;
940 return mapind(scrolling_map, result.screen);
941 }
942
943 return -1;
944 }
945
946 int32_t get_ref_map_index(int32_t ref)
947 {
948 if (ref >= 0)
949 return ref;
950
951 auto result = decode_mapdata_ref(ref);
952 if (result.current())
953 {
954 return map_screen_index(cur_map, result.screen);
955 }
956 else if (result.scrolling())
957 {
958 return map_screen_index(scrolling_map, result.screen);
959 }
960
961 return -1;
962 }
963
964 template <typename T>
965 273449435 static T* ResolveSprite(int32_t uid, const char* name)
966 {
967
8/10
✓ Branch 0 taken 43219390 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1641473 times.
✓ Branch 3 taken 597888 times.
✓ Branch 4 taken 162664717 times.
✓ Branch 5 taken 2612 times.
✓ Branch 6 taken 58765181 times.
✓ Branch 7 taken 183114 times.
✓ Branch 8 taken 6375060 times.
✗ Branch 9 not taken.
273449435 if (!uid)
968 {
969
6/20
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 597888 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 597888 times.
✓ Branch 8 taken 2612 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 2612 times.
✓ Branch 12 taken 183114 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 183114 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
783614 scripting_log_error_with_context("Invalid sprite: null pointer");
970 783614 return nullptr;
971 }
972
973
8/10
✗ Branch 0 not taken.
✓ Branch 1 taken 43219390 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 1641293 times.
✓ Branch 4 taken 7107 times.
✓ Branch 5 taken 162657610 times.
✓ Branch 6 taken 20166 times.
✓ Branch 7 taken 58745015 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6375060 times.
272665821 if (auto s = sprite::getByUID(uid))
974 {
975
9/18
✗ Branch 0 not taken.
✓ Branch 1 taken 43219390 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1641293 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1641293 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 162657610 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 162657610 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58745015 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 58745015 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6375060 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 6375060 times.
272638368 if (auto s2 = dynamic_cast<T*>(s))
976 272638368 return s2;
977
978 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
979 return nullptr;
980 }
981
982 27453 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite does not exist", uid);
983 27453 return nullptr;
984 273449435 }
985
986 43219390 sprite* ResolveBaseSprite(int32_t uid)
987 {
988 43219390 return ResolveSprite<sprite>(uid, "sprite");
989 }
990
991 2239361 item* ResolveItemSprite(int32_t uid)
992 {
993 2239361 return ResolveSprite<item>(uid, "item");
994 }
995
996 162667317 enemy* ResolveNpc(int32_t uid)
997 {
998 162667317 return ResolveSprite<enemy>(uid, "npc");
999 }
1000
1001 static weapon* ResolveEWeapon_checkSpriteList(int32_t uid)
1002 {
1003 // Check here first (for the error logging.)
1004 const char* name = "eweapon";
1005 auto spr = ResolveSprite<weapon>(uid, name);
1006
1007 // Double check this is from the right sprite list.
1008 if (spr && !Ewpns.getByUID(uid))
1009 {
1010 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
1011 return nullptr;
1012 }
1013
1014 return spr;
1015 }
1016
1017 598 static weapon* ResolveLWeapon_checkSpriteList(int32_t uid)
1018 {
1019 // Check here first (for the error logging.)
1020 598 const char* name = "lweapon";
1021 598 auto spr = ResolveSprite<weapon>(uid, name);
1022
1023 // Double check this is from the right sprite list.
1024
2/4
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 598 times.
598 if (spr && !Lwpns.getByUID(uid))
1025 {
1026 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
1027 return nullptr;
1028 }
1029
1030 598 return spr;
1031 598 }
1032
1033 // For compat, get the first `combo_trigger` of the current `ri->combosref`
1034 3224 combo_trigger* get_first_combo_trigger()
1035 {
1036
2/4
✓ Branch 0 taken 3224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3224 times.
3224 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
1037 return nullptr;
1038
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 3085 times.
3224 if(combobuf[ri->combosref].triggers.empty())
1039 139 return &(combobuf[ri->combosref].triggers.emplace_back());
1040 3085 return &(combobuf[ri->combosref].triggers[0]);
1041 3224 }
1042 // Get the combo trigger pointed to by `ref` (usually ri->combotrigref)
1043 combo_trigger* get_combo_trigger(dword ref)
1044 {
1045 byte idx = (ref >> 24) & 0xFF;
1046 dword cid = ref & 0x00FFFFFF;
1047 if(cid >= MAXCOMBOS)
1048 {
1049 scripting_log_error_with_context("Invalid combotrigger ID: {}-{}", idx, cid);
1050 return nullptr;
1051 }
1052 newcombo& cmb = combobuf[cid];
1053 if(idx >= cmb.triggers.size())
1054 {
1055 scripting_log_error_with_context("Invalid combotrigger ID: {}-{}", idx, cid);
1056 return nullptr;
1057 }
1058 return &(cmb.triggers[idx]);
1059 }
1060 // Get the combo ID of the trigger pointed to by `ref` (usually ri->combotrigref)
1061 dword get_combo_from_trigger_ref(dword ref)
1062 {
1063 dword cid = ref & 0x00FFFFFF;
1064 DCHECK(cid < MAXCOMBOS);
1065 return cid;
1066 }
1067
1068 ///------------------------------------------------//
1069 // Pointer Handling Functions //
1070 ///------------------------------------------------//
1071
1072 //LWeapon Helper
1073 class LwpnH : public SH
1074 {
1075
1076 public:
1077
1078
1079 static defWpnSprite getDefWeaponSprite(weapon *wp)
1080 {
1081 switch(wp->id)
1082 {
1083 case wNone: return ws_0;
1084 case wSword: return ws_0;
1085 case wBeam: return wsBeam;
1086 case wBrang : return wsBrang;
1087 case wBomb: return wsBomb;
1088 case wSBomb: return wsSBomb;
1089 case wLitBomb: return wsBombblast;
1090 case wLitSBomb: return wsBombblast;
1091 case wArrow: return wsArrow;
1092 case wRefArrow: return wsArrow;
1093 case wFire: return wsFire;
1094 case wRefFire: return wsFire;
1095 case wRefFire2: return wsFire;
1096 case wWhistle: return wsUnused45;
1097 case wBait: return wsBait;
1098 case wWand: return wsWandHandle;
1099 case wMagic: return wsMagic;
1100 case wCatching: return wsUnused45;
1101 case wWind: return wsWind;
1102 case wRefMagic: return wsRefMagic;
1103 case wRefFireball: return wsRefFireball;
1104 case wRefRock: return wsRock;
1105 case wHammer: return wsHammer;
1106 case wHookshot: return wsHookshotHead;
1107 case wHSHandle: return wsHookshotHandle;
1108 case wHSChain: return wsHookshotChainH;
1109 case wSSparkle: return wsSilverSparkle;
1110 case wFSparkle: return wsGoldSparkle;
1111 case wSmack: return wsHammerSmack;
1112 case wPhantom: return wsUnused45;
1113 case wCByrna: return wsByrnaCane;
1114 case wRefBeam: return wsRefBeam;
1115 case wStomp: return wsUnused45;
1116 case lwMax: return wsUnused45;
1117 case wScript1:
1118 case wScript2:
1119 case wScript3:
1120 case wScript4:
1121 case wScript5:
1122 case wScript6:
1123 case wScript7:
1124 case wScript8:
1125 case wScript9:
1126 case wScript10: return ws_0;
1127 case wIce: return wsIce; //new
1128 case wFlame: return wsEFire2; //new
1129 //not implemented; t/b/a
1130 case wSound:
1131 case wThrown:
1132 case wPot:
1133 case wLit:
1134 case wBombos:
1135 case wEther:
1136 case wQuake:
1137 case wSword180:
1138 case wSwordLA: return wsUnused45;
1139
1140 case ewFireball: return wsFireball2;
1141 case ewArrow: return wsEArrow;
1142 case ewBrang: return wsBrang;
1143 case ewSword: return wsEBeam;
1144 case ewRock: return wsRock;
1145 case ewMagic: return wsEMagic;
1146 case ewBomb: return wsEBomb;
1147 case ewSBomb: return wsESbomb;
1148 case ewLitBomb: return wsEBombblast;
1149 case ewLitSBomb: return wsESbombblast;
1150 case ewFireTrail: return wsEFiretrail;
1151 case ewFlame: return wsEFire;
1152 case ewWind: return wsEWind;
1153 case ewFlame2: return wsEFire2;
1154 case ewFlame2Trail: return wsEFiretrail2;
1155 case ewIce: return wsIce;
1156 case ewFireball2: return wsFireball2;
1157 default: return wsUnused45;
1158 }
1159 };
1160
1161 19653 static int32_t loadWeapon(const int32_t uid)
1162 {
1163 19653 tempweapon = ResolveSprite<weapon>(uid, "lweapon");
1164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19653 times.
19653 if (!tempweapon)
1165 return _InvalidSpriteUID;
1166
1167 19653 return _NoError;
1168 19653 }
1169
1170 19653 static INLINE weapon *getWeapon()
1171 {
1172 19653 return tempweapon;
1173 }
1174
1175 36017 static INLINE void clearTemp()
1176 {
1177 36017 tempweapon = NULL;
1178 36017 }
1179
1180 private:
1181
1182 static weapon *tempweapon;
1183 };
1184
1185 weapon *LwpnH::tempweapon = NULL;
1186
1187 //EWeapon Helper
1188 class EwpnH : public SH
1189 {
1190
1191 public:
1192
1193 defWpnSprite getDefWeaponSprite(weapon *wp)
1194 {
1195 switch(wp->id)
1196 {
1197 case wNone: return ws_0;
1198 case wSword: return ws_0;
1199 case wBeam: return wsBeam;
1200 case wBrang : return wsBrang;
1201 case wBomb: return wsBomb;
1202 case wSBomb: return wsSBomb;
1203 case wLitBomb: return wsBombblast;
1204 case wLitSBomb: return wsBombblast;
1205 case wArrow: return wsArrow;
1206 case wRefArrow: return wsArrow;
1207 case wFire: return wsFire;
1208 case wRefFire: return wsFire;
1209 case wRefFire2: return wsFire;
1210 case wWhistle: return wsUnused45;
1211 case wBait: return wsBait;
1212 case wWand: return wsWandHandle;
1213 case wMagic: return wsMagic;
1214 case wCatching: return wsUnused45;
1215 case wWind: return wsWind;
1216 case wRefMagic: return wsRefMagic;
1217 case wRefFireball: return wsRefFireball;
1218 case wRefRock: return wsRock;
1219 case wHammer: return wsHammer;
1220 case wHookshot: return wsHookshotHead;
1221 case wHSHandle: return wsHookshotHandle;
1222 case wHSChain: return wsHookshotChainH;
1223 case wSSparkle: return wsSilverSparkle;
1224 case wFSparkle: return wsGoldSparkle;
1225 case wSmack: return wsHammerSmack;
1226 case wPhantom: return wsUnused45;
1227 case wCByrna: return wsByrnaCane;
1228 case wRefBeam: return wsRefBeam;
1229 case wStomp: return wsUnused45;
1230 case lwMax: return wsUnused45;
1231 case wScript1:
1232 case wScript2:
1233 case wScript3:
1234 case wScript4:
1235 case wScript5:
1236 case wScript6:
1237 case wScript7:
1238 case wScript8:
1239 case wScript9:
1240 case wScript10: return ws_0;
1241 case wIce: return wsIce; //new
1242 case wFlame: return wsEFire2; //new
1243 //not implemented; t/b/a
1244 case wSound:
1245 case wThrown:
1246 case wPot:
1247 case wLit:
1248 case wBombos:
1249 case wEther:
1250 case wQuake:
1251 case wSword180:
1252 case wSwordLA: return wsUnused45;
1253
1254 case ewFireball: return wsFireball2;
1255 case ewArrow: return wsEArrow;
1256 case ewBrang: return wsBrang;
1257 case ewSword: return wsEBeam;
1258 case ewRock: return wsRock;
1259 case ewMagic: return wsEMagic;
1260 case ewBomb: return wsEBomb;
1261 case ewSBomb: return wsESbomb;
1262 case ewLitBomb: return wsEBombblast;
1263 case ewLitSBomb: return wsESbombblast;
1264 case ewFireTrail: return wsEFiretrail;
1265 case ewFlame: return wsEFire;
1266 case ewWind: return wsEWind;
1267 case ewFlame2: return wsEFire2;
1268 case ewFlame2Trail: return wsEFiretrail2;
1269 case ewIce: return wsIce;
1270 case ewFireball2: return wsFireball2;
1271 default: return wsUnused45;
1272 }
1273 };
1274
1275 208946 static int32_t loadWeapon(const int32_t uid)
1276 {
1277 208946 tempweapon = ResolveSprite<weapon>(uid, "eweapon");
1278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208946 times.
208946 if (!tempweapon)
1279 return _InvalidSpriteUID;
1280
1281 208946 return _NoError;
1282 208946 }
1283
1284 208946 static INLINE weapon *getWeapon()
1285 {
1286 208946 return tempweapon;
1287 }
1288
1289 36017 static INLINE void clearTemp()
1290 {
1291 36017 tempweapon = NULL;
1292 36017 }
1293
1294 private:
1295
1296 static weapon *tempweapon;
1297 };
1298
1299 weapon *EwpnH::tempweapon = NULL;
1300
1301 36017 void clearScriptHelperData()
1302 {
1303 36017 GuyH::clearTemp();
1304 36017 LwpnH::clearTemp();
1305 36017 EwpnH::clearTemp();
1306 36017 ItemH::clearTemp();
1307 36017 }
1308 ////END HELPER FUNCTIONS
1309
1310 static int32_t numInstructions = 0; // Used to detect hangs
1311 static bool scriptCanSave = true;
1312
1313 725761605 static ScriptEngineData& get_script_engine_data(ScriptType type, int index)
1314 {
1315
8/8
✓ Branch 0 taken 693027120 times.
✓ Branch 1 taken 32734485 times.
✓ Branch 2 taken 693023661 times.
✓ Branch 3 taken 3459 times.
✓ Branch 4 taken 660495602 times.
✓ Branch 5 taken 32528059 times.
✓ Branch 6 taken 30042 times.
✓ Branch 7 taken 660465560 times.
725761605 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1316 {
1317 // `index` is used for dmapref, not for different script engine data.
1318 65296045 index = 0;
1319 65296045 }
1320
2/2
✓ Branch 0 taken 725685587 times.
✓ Branch 1 taken 76018 times.
725761605 if (type == ScriptType::EngineSubscreen)
1321 {
1322 // `index` is used for subdataref, not for different script engine data.
1323 76018 index = 0;
1324 76018 }
1325
1326 725761605 return scriptEngineDatas[{type, index}];
1327 }
1328
1329 1003067 static bool script_engine_data_exists(ScriptType type, int index)
1330 {
1331
5/8
✓ Branch 0 taken 999702 times.
✓ Branch 1 taken 3365 times.
✓ Branch 2 taken 999702 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 999702 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 999702 times.
1003067 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1332 {
1333 // `index` is used for dmapref, not for different script engine data.
1334 3365 index = 0;
1335 3365 }
1336
1/2
✓ Branch 0 taken 1003067 times.
✗ Branch 1 not taken.
1003067 if (type == ScriptType::EngineSubscreen)
1337 {
1338 // `index` is used for subdataref, not for different script engine data.
1339 index = 0;
1340 }
1341
1342 1003067 return scriptEngineDatas.contains({type, index});
1343 }
1344
1345 46 static ScriptEngineData& get_script_engine_data(ScriptType type)
1346 {
1347 46 return get_script_engine_data(type, 0);
1348 }
1349
1350 1116 void FFScript::clear_script_engine_data()
1351 {
1352 1116 scriptEngineDatas.clear();
1353 1116 }
1354
1355 2334686 void FFScript::reset_script_engine_data(ScriptType type, int index)
1356 {
1357 2334686 get_script_engine_data(type, index).reset();
1358 2334686 }
1359
1360 80806 void on_reassign_script_engine_data(ScriptType type, int index)
1361 {
1362 80806 auto& data = get_script_engine_data(type, index);
1363 80806 data.clear_ref();
1364 80806 FFScript::deallocateAllScriptOwned(type, index);
1365 80806 }
1366
1367 1129511 void FFScript::clear_script_engine_data(ScriptType type, int index)
1368 {
1369
4/8
✓ Branch 0 taken 1129511 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1129511 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1129511 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1129511 times.
1129511 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1370 {
1371 // `index` is used for dmapref, not for different script engine data.
1372 index = 0;
1373 }
1374
1/2
✓ Branch 0 taken 1129511 times.
✗ Branch 1 not taken.
1129511 if (type == ScriptType::EngineSubscreen)
1375 {
1376 // `index` is used for subdataref, not for different script engine data.
1377 index = 0;
1378 }
1379
1380 1129511 auto it = scriptEngineDatas.find({type, index});
1381
2/2
✓ Branch 0 taken 1129355 times.
✓ Branch 1 taken 156 times.
1129511 if (it != scriptEngineDatas.end())
1382 {
1383 156 scriptEngineDatas.erase(it);
1384 156 }
1385 1129511 }
1386
1387 135680 void FFScript::clear_script_engine_data_of_type(ScriptType type)
1388 {
1389 282511700 std::erase_if(scriptEngineDatas, [&](auto& kv) { return kv.first.first == type; });
1390 135680 }
1391
1392 refInfo& FFScript::ref(ScriptType type, int index)
1393 {
1394 return get_script_engine_data(type, index).ref;
1395 }
1396
1397 307 void FFScript::clear_ref(ScriptType type, int index)
1398 {
1399 307 get_script_engine_data(type, index).clear_ref();
1400 307 }
1401
1402 65044778 byte& FFScript::doscript(ScriptType type, int index)
1403 {
1404
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 65044778 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
65044778 if (type == ScriptType::Generic && unsigned(index) < NUMSCRIPTSGENERIC)
1405 return user_genscript::get(index).doscript();
1406 65044778 return get_script_engine_data(type, index).doscript;
1407 65044778 }
1408
1409 531835954 bool& FFScript::waitdraw(ScriptType type, int index)
1410 {
1411 531835954 return get_script_engine_data(type, index).waitdraw;
1412 }
1413
1414 26670160 static bool set_current_script_engine_data(ScriptEngineData& data, ScriptType type, int script, int index)
1415 {
1416 26670160 bool got_initialized = false;
1417
1418 26670160 ri = &data.ref;
1419 26670160 stack = &data.stack;
1420 26670160 ret_stack = &data.ret_stack;
1421
1422 // By default, make `Screen->` refer to the top-left screen.
1423 // Will be set to something more specific for relevant script types.
1424 26670160 ri->screenref = cur_screen;
1425
1426
16/18
✗ Branch 0 not taken.
✓ Branch 1 taken 11172236 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 212924 times.
✓ Branch 4 taken 147334 times.
✓ Branch 5 taken 7460 times.
✓ Branch 6 taken 15539 times.
✓ Branch 7 taken 11113319 times.
✓ Branch 8 taken 2141155 times.
✓ Branch 9 taken 1542 times.
✓ Branch 10 taken 1330355 times.
✓ Branch 11 taken 74551 times.
✓ Branch 12 taken 114 times.
✓ Branch 13 taken 12244 times.
✓ Branch 14 taken 1402 times.
✓ Branch 15 taken 15162 times.
✓ Branch 16 taken 56311 times.
✓ Branch 17 taken 368512 times.
26670160 switch (type)
1427 {
1428 case ScriptType::FFC:
1429 {
1430 11172236 curscript = ffscripts[script];
1431 11172236 ffcdata* ffc = get_ffc(index);
1432
1433
2/2
✓ Branch 0 taken 11145573 times.
✓ Branch 1 taken 26663 times.
11172236 if (!data.initialized)
1434 {
1435 26663 got_initialized = true;
1436 26663 mapscr* scr = get_scr(ffc->screen_spawned);
1437 26663 memcpy(ri->d, scr->ffcs[index % 128].initd, 8 * sizeof(int32_t));
1438 26663 data.initialized = true;
1439 26663 }
1440
1441
2/2
✓ Branch 0 taken 1644364 times.
✓ Branch 1 taken 9527872 times.
11172236 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? ffc->getUID() : index;
1442 11172236 ri->screenref = ffc->screen_spawned;
1443 }
1444 11172236 break;
1445
1446 case ScriptType::NPC:
1447 {
1448 enemy *spr = (enemy*)guys.getByUID(index);
1449 curscript = guyscripts[script];
1450
1451 if (!data.initialized)
1452 {
1453 got_initialized = true;
1454 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1455 data.initialized = 1;
1456 }
1457
1458 ri->guyref = index;
1459 ri->screenref = spr->screen_spawned;
1460 }
1461 break;
1462
1463 case ScriptType::Lwpn:
1464 {
1465 212924 weapon *spr = (weapon*)Lwpns.getByUID(index);
1466 212924 curscript = lwpnscripts[script];
1467
1468
2/2
✓ Branch 0 taken 150555 times.
✓ Branch 1 taken 62369 times.
212924 if (!data.initialized)
1469 {
1470 62369 got_initialized = true;
1471 62369 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1472 62369 data.initialized = 1;
1473 62369 }
1474
1475 212924 ri->lwpn = index;
1476 212924 ri->screenref = spr->screen_spawned;
1477 }
1478 212924 break;
1479
1480 case ScriptType::Ewpn:
1481 {
1482 147334 weapon *spr = (weapon*)Ewpns.getByUID(index);
1483 147334 curscript = ewpnscripts[script];
1484
1485
2/2
✓ Branch 0 taken 145713 times.
✓ Branch 1 taken 1621 times.
147334 if (!data.initialized)
1486 {
1487 1621 got_initialized = true;
1488 1621 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1489 1621 data.initialized = 1;
1490 1621 }
1491
1492 147334 ri->ewpn = index;
1493 147334 ri->screenref = spr->screen_spawned;
1494 }
1495 147334 break;
1496
1497 case ScriptType::ItemSprite:
1498 {
1499 7460 item *spr = (item*)items.getByUID(index);
1500 7460 curscript = itemspritescripts[script];
1501
1502
2/2
✓ Branch 0 taken 7210 times.
✓ Branch 1 taken 250 times.
7460 if (!data.initialized)
1503 {
1504 250 got_initialized = true;
1505 250 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1506 250 data.initialized = 1;
1507 250 }
1508
1509 7460 ri->itemref = index;
1510 7460 ri->screenref = spr->screen_spawned;
1511 }
1512 7460 break;
1513
1514 case ScriptType::Item:
1515 {
1516 15539 int32_t i = index;
1517 15539 int32_t new_i = 0;
1518
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
1519
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
15539 new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
1520
1521 15539 curscript = itemscripts[script];
1522
1523
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 2049 times.
15539 if (!data.initialized)
1524 {
1525 2049 got_initialized = true;
1526
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 memcpy(ri->d, ( collect ) ? itemsbuf[new_i].initiald : itemsbuf[i].initiald, 8 * sizeof(int32_t));
1527 2049 data.initialized = true;
1528 2049 }
1529
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 ri->idata = ( collect ) ? new_i : i; //'this' pointer
1530 }
1531 15539 break;
1532
1533 case ScriptType::Global:
1534 {
1535 11113319 curscript = globalscripts[script];
1536
2/2
✓ Branch 0 taken 11110135 times.
✓ Branch 1 taken 3184 times.
11113319 if (!data.initialized)
1537 {
1538 3184 got_initialized = true;
1539 3184 data.initialized = 1;
1540
1541 // If this compat QR is on, scripts can run before ~Init and set global variables.
1542 // Before overwriting them with 0, get rid of object references held by global variables.
1543
6/6
✓ Branch 0 taken 2673 times.
✓ Branch 1 taken 511 times.
✓ Branch 2 taken 1120 times.
✓ Branch 3 taken 1553 times.
✓ Branch 4 taken 19 times.
✓ Branch 5 taken 1101 times.
3184 if (get_qr(qr_OLD_INIT_SCRIPT_TIMING) && ZScriptVersion::gc() && script == GLOBAL_SCRIPT_INIT)
1544 {
1545
2/2
✓ Branch 0 taken 19456 times.
✓ Branch 1 taken 19 times.
19475 for (int i = 0; i < MAX_SCRIPT_REGISTERS; i++)
1546 19456 script_object_ref_dec(game->global_d[i]);
1547 19 }
1548 3184 }
1549 }
1550 11113319 break;
1551
1552 case ScriptType::Generic:
1553 {
1554 2141155 user_genscript& scr = user_genscript::get(script);
1555 2141155 curscript = genericscripts[script];
1556 2141155 scr.waitevent = false;
1557
2/2
✓ Branch 0 taken 2140567 times.
✓ Branch 1 taken 588 times.
2141155 if(!data.initialized)
1558 {
1559 588 got_initialized = true;
1560 588 scr.initd.copy_to(ri->d, 8);
1561 588 data.initialized = true;
1562 588 }
1563 2141155 ri->genericdataref = script;
1564 }
1565 2141155 break;
1566
1567 case ScriptType::GenericFrozen:
1568 {
1569 1542 user_genscript& scr = user_genscript::get(script);
1570 1542 curscript = genericscripts[script];
1571
2/2
✓ Branch 0 taken 1532 times.
✓ Branch 1 taken 10 times.
1542 if(!data.initialized)
1572 {
1573 10 got_initialized = true;
1574 10 scr.initd.copy_to(ri->d, 8);
1575 10 data.initialized = true;
1576 10 }
1577 1542 ri->genericdataref = script;
1578 }
1579 1542 break;
1580
1581 case ScriptType::Hero:
1582 {
1583 1330355 curscript = playerscripts[script];
1584 1330355 ri->screenref = hero_screen;
1585
2/2
✓ Branch 0 taken 1329870 times.
✓ Branch 1 taken 485 times.
1330355 if (!data.initialized)
1586 {
1587 485 got_initialized = true;
1588 485 data.initialized = 1;
1589 485 }
1590 }
1591 1330355 break;
1592
1593 case ScriptType::DMap:
1594 {
1595 74551 curscript = dmapscripts[script];
1596 74551 ri->dmapsref = index;
1597 //how do we clear initialised on dmap change?
1598
2/2
✓ Branch 0 taken 74449 times.
✓ Branch 1 taken 102 times.
74551 if ( !data.initialized )
1599 {
1600 102 got_initialized = true;
1601
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 102 times.
918 for ( int32_t q = 0; q < 8; q++ )
1602 {
1603 816 ri->d[q] = DMaps[ri->dmapsref].initD[q];// * 10000;
1604 816 }
1605 102 data.initialized = true;
1606 102 }
1607 }
1608 74551 break;
1609
1610 case ScriptType::OnMap:
1611 {
1612 114 curscript = dmapscripts[script];
1613 114 ri->dmapsref = index;
1614
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 3 times.
114 if (!data.initialized)
1615 {
1616 3 got_initialized = true;
1617
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
27 for ( int32_t q = 0; q < 8; q++ )
1618 {
1619 24 ri->d[q] = DMaps[ri->dmapsref].onmap_initD[q];
1620 24 }
1621 3 data.initialized = true;
1622 3 }
1623 }
1624 114 break;
1625
1626 case ScriptType::ScriptedActiveSubscreen:
1627 {
1628 12244 curscript = dmapscripts[script];
1629 12244 ri->dmapsref = index;
1630
2/2
✓ Branch 0 taken 12203 times.
✓ Branch 1 taken 41 times.
12244 if (!data.initialized)
1631 {
1632 41 got_initialized = true;
1633
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 41 times.
369 for ( int32_t q = 0; q < 8; q++ )
1634 {
1635 328 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1636 328 }
1637 41 data.initialized = true;
1638 41 }
1639 }
1640 12244 break;
1641
1642 case ScriptType::ScriptedPassiveSubscreen:
1643 {
1644 1402 curscript = dmapscripts[script];
1645 1402 ri->dmapsref = index;
1646
2/2
✓ Branch 0 taken 1400 times.
✓ Branch 1 taken 2 times.
1402 if (!data.initialized)
1647 {
1648 2 got_initialized = true;
1649
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 for ( int32_t q = 0; q < 8; q++ )
1650 {
1651 16 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1652 16 }
1653 2 data.initialized = true;
1654 2 }
1655 }
1656 1402 break;
1657 case ScriptType::EngineSubscreen:
1658 {
1659 15162 curscript = subscreenscripts[script];
1660 15162 ri->subdataref = get_subref(-1, sstACTIVE);
1661 15450 auto [ptr,_ty] = load_subdata(ri->subdataref);
1662
1663
3/4
✓ Branch 0 taken 15162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15126 times.
✓ Branch 3 taken 36 times.
15162 if (ptr && !data.initialized)
1664 {
1665 36 got_initialized = true;
1666
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 36 times.
324 for ( int32_t q = 0; q < 8; q++ )
1667 {
1668 288 ri->d[q] = ptr->initd[q];
1669 288 }
1670 36 data.initialized = true;
1671 36 }
1672 }
1673 15162 break;
1674
1675 case ScriptType::Screen:
1676 {
1677 56311 curscript = screenscripts[script];
1678
1679
2/2
✓ Branch 0 taken 56192 times.
✓ Branch 1 taken 119 times.
56311 if (!data.initialized)
1680 {
1681 119 got_initialized = true;
1682 119 mapscr* scr = get_scr(index);
1683
2/2
✓ Branch 0 taken 952 times.
✓ Branch 1 taken 119 times.
1071 for ( int32_t q = 0; q < 8; q++ )
1684 {
1685 952 ri->d[q] = scr->screeninitd[q];// * 10000;
1686 952 }
1687 119 data.initialized = true;
1688 119 }
1689
1690 56311 ri->screenref = index;
1691 }
1692 56311 break;
1693
1694 case ScriptType::Combo:
1695 {
1696 368512 curscript = comboscripts[script];
1697
1698 368512 rpos_t rpos = combopos_ref_to_rpos(index);
1699 368512 int32_t lyr = combopos_ref_to_layer(index);
1700 368512 auto rpos_handle = get_rpos_handle(rpos, lyr);
1701 368512 int32_t id = rpos_handle.data();
1702
2/2
✓ Branch 0 taken 360187 times.
✓ Branch 1 taken 8325 times.
368512 if (!data.initialized)
1703 {
1704 8325 got_initialized = true;
1705 8325 memset(ri->d, 0, 8 * sizeof(int32_t));
1706
2/2
✓ Branch 0 taken 66600 times.
✓ Branch 1 taken 8325 times.
74925 for ( int32_t q = 0; q < 8; q++ )
1707 66600 ri->d[q] = combobuf[id].initd[q];
1708 8325 data.initialized = true;
1709 8325 }
1710
1711 368512 ri->combosref = id; //'this' pointer
1712 368512 ri->comboposref = index; //used for X(), Y(), Layer(), and so forth.
1713 368512 ri->screenref = rpos_handle.screen;
1714 368512 break;
1715 }
1716 }
1717
1718
2/2
✓ Branch 0 taken 26564313 times.
✓ Branch 1 taken 105847 times.
26670160 if (got_initialized)
1719 105847 ri->pc = curscript->pc;
1720
1721 26670160 return got_initialized;
1722 }
1723
1724 643320843 static ffcdata *ResolveFFCWithID(ffc_id_t id)
1725 {
1726
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 643320612 times.
643320843 if (BC::checkFFC(id) != SH::_NoError)
1727 231 return nullptr;
1728
1729 643320612 ffcdata* ffc = get_ffc(id);
1730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643320612 times.
643320612 if (!ffc)
1731 scripting_log_error_with_context("Invalid ffc using ID = {}", id);
1732
1733 643320612 return ffc;
1734 643320843 }
1735
1736 646327350 static ffcdata *ResolveFFC(int32_t ffcref)
1737 {
1738
2/2
✓ Branch 0 taken 6375060 times.
✓ Branch 1 taken 639952290 times.
646327350 if (ZScriptVersion::ffcRefIsSpriteId())
1739 6375060 return ResolveSprite<ffcdata>(ffcref, "ffc");
1740
1741 639952290 return ResolveFFCWithID(ffcref);
1742 646327350 }
1743
1744 528 static mapscr* ResolveMapdataScr(int32_t mapref)
1745 {
1746 528 auto mapdata = decode_mapdata_ref(mapref);
1747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
528 if (!mapdata.scr)
1748 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1749 528 return mapdata.scr;
1750 }
1751
1752 static rpos_handle_t ResolveMapdataPos(int32_t mapref, int pos)
1753 {
1754 auto mapdata = decode_mapdata_ref(mapref);
1755 if (!mapdata.scr)
1756 {
1757 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1758 return rpos_handle_t{};
1759 }
1760
1761 return mapdata.resolve_pos(pos);
1762 }
1763
1764 86699825 int mapdata::max_pos()
1765 {
1766
2/2
✓ Branch 0 taken 69348879 times.
✓ Branch 1 taken 17350946 times.
86699825 if (type == mapdata_type::TemporaryCurrentRegion)
1767 69348879 return (int)region_max_rpos;
1768
1769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (type == mapdata_type::TemporaryScrollingRegion)
1770 return (int)scrolling_region.screen_count * 176 - 1;
1771
1772 17350946 return 175;
1773 86699825 }
1774
1775 86699825 rpos_handle_t mapdata::resolve_pos(int pos)
1776 {
1777
3/4
✓ Branch 0 taken 85433327 times.
✓ Branch 1 taken 1266498 times.
✓ Branch 2 taken 85433327 times.
✗ Branch 3 not taken.
86699825 if (!screenscrolling && scrolling())
1778 {
1779 int32_t mapref = create_mapdata_temp_ref(type, screen, layer);
1780 scripting_log_error_with_context("mapdata id is invalid: {} - screen is not scrolling right now", mapref);
1781 return rpos_handle_t{};
1782 }
1783
1784 // mapdata loaded via `Game->LoadTempScreen(layer)` have access to the entire region.
1785
2/2
✓ Branch 0 taken 69348879 times.
✓ Branch 1 taken 17350946 times.
86699825 if (type == mapdata_type::TemporaryCurrentRegion)
1786 {
1787 69348879 rpos_t rpos = (rpos_t)pos;
1788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69348879 times.
69348879 if (BC::checkComboRpos(rpos) != SH::_NoError)
1789 return rpos_handle_t{};
1790
1791 69348879 return get_rpos_handle(rpos, layer);
1792 }
1793
1794 // mapdata loaded via `Game->LoadScrollingScreen(layer)` have access to the entire scrolling region.
1795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (type == mapdata_type::TemporaryScrollingRegion)
1796 {
1797 rpos_t rpos = (rpos_t)pos;
1798 rpos_t max = (rpos_t)(scrolling_region.screen_count * 176 - 1);
1799 if (BC::checkBoundsRpos(rpos, (rpos_t)0, max) != SH::_NoError)
1800 return rpos_handle_t{};
1801
1802 int origin_screen = scrolling_region.origin_screen;
1803 int origin_screen_x = origin_screen % 16;
1804 int origin_screen_y = origin_screen / 16;
1805 int scr_index = static_cast<int32_t>(rpos) / 176;
1806 int scr_x = origin_screen_x + scr_index%cur_region.screen_width;
1807 int scr_y = origin_screen_y + scr_index/cur_region.screen_width;
1808 int screen = map_scr_xy_to_index(scr_x, scr_y);
1809 mapscr* scr = FFCore.ScrollingScreensAll[screen * 7 + layer];
1810
1811 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
1812 }
1813
1814 // Otherwise, access is limited to just one screen.
1815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (BC::checkComboPos(pos) != SH::_NoError)
1816 return rpos_handle_t{};
1817
1818
1/2
✓ Branch 0 taken 17350946 times.
✗ Branch 1 not taken.
17350946 if (type == mapdata_type::CanonicalScreen)
1819 17350946 return {scr, screen, 0, (rpos_t)pos, pos};
1820
1821 if (scrolling())
1822 {
1823 if (!scr->is_valid())
1824 return rpos_handle_t{};
1825
1826 return {scr, screen, layer, (rpos_t)pos, pos};
1827 }
1828
1829 rpos_t rpos = POS_TO_RPOS(pos, screen);
1830 if (BC::checkComboRpos(rpos) != SH::_NoError)
1831 return rpos_handle_t{};
1832
1833 return {scr, screen, layer, rpos, pos};
1834 86699825 }
1835
1836 1557619 ffc_handle_t mapdata::resolve_ffc_handle(int index)
1837 {
1838 1557619 index -= 1;
1839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1557619 times.
1557619 if (BC::checkMapdataFFC(index) != SH::_NoError)
1840 return ffc_handle_t{};
1841
1842 1557619 int screen_index_offset = 0;
1843
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1557619 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1557619 if (current() && layer == 0)
1844 screen_index_offset = get_region_screen_offset(screen);
1845
1846 1557619 return *scr->getFFCHandle(index, screen_index_offset);
1847 1557619 }
1848
1849 1557411 ffcdata* mapdata::resolve_ffc(int index)
1850 {
1851 1557411 return resolve_ffc_handle(index).ffc;
1852 }
1853
1854 2045 static ffc_handle_t ResolveMapdataFFC(int32_t mapref, int index)
1855 {
1856 2045 index -= 1;
1857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2045 times.
2045 if (BC::checkMapdataFFC(index) != SH::_NoError)
1858 return ffc_handle_t{};
1859
1860 2045 auto result = decode_mapdata_ref(mapref);
1861
1/2
✓ Branch 0 taken 2045 times.
✗ Branch 1 not taken.
2045 if (!result.scr)
1862 {
1863 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1864 return ffc_handle_t{};
1865 }
1866
1867 2045 int screen_index_offset = 0;
1868
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2045 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2045 if (result.current() && result.layer == 0)
1869 screen_index_offset = get_region_screen_offset(result.screen);
1870
1871 2045 return *result.scr->getFFCHandle(index, screen_index_offset);
1872 2045 }
1873
1874 int32_t genscript_timing = SCR_TIMING_START_FRAME;
1875 static word max_valid_genscript;
1876
1877 216064 void user_genscript::clear()
1878 {
1879 216064 wait_atleast = true;
1880 216064 waituntil = SCR_TIMING_START_FRAME;
1881 216064 waitevent = false;
1882 216064 exitState = 0;
1883 216064 reloadState = 0;
1884 216064 eventstate = 0;
1885 216064 initd.clear();
1886 216064 data.clear();
1887 216064 quit();
1888 216064 }
1889 537 void user_genscript::launch()
1890 {
1891 537 quit();
1892 537 doscript() = true;
1893 537 wait_atleast = true;
1894 537 waituntil = SCR_TIMING_START_FRAME;
1895 537 waitevent = false;
1896 537 }
1897 216648 void user_genscript::quit()
1898 {
1899
1/2
✓ Branch 0 taken 216648 times.
✗ Branch 1 not taken.
216648 if(indx > -1)
1900 {
1901 216648 FFCore.destroyScriptableObject(ScriptType::Generic, indx);
1902 216648 }
1903 216648 _doscript = false;
1904 216648 }
1905 265924178 byte& user_genscript::doscript()
1906 {
1907 265924178 return _doscript;
1908 }
1909 512 byte const& user_genscript::doscript() const
1910 {
1911 512 return _doscript;
1912 }
1913
1914
1915 278675308 user_genscript& user_genscript::get(int ind)
1916 {
1917
3/4
✓ Branch 0 taken 278674885 times.
✓ Branch 1 taken 423 times.
✓ Branch 2 taken 278674885 times.
✗ Branch 3 not taken.
278675308 if(ind < 1 || ind >= NUMSCRIPTSGENERIC)
1918 423 ind = 0;
1919 278675308 user_scripts[ind].indx = ind;
1920 278675308 return user_scripts[ind];
1921 }
1922
3/4
✓ Branch 0 taken 210944 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 210532 times.
✓ Branch 3 taken 412 times.
210944 user_genscript user_genscript::user_scripts[NUMSCRIPTSGENERIC];
1923
1924 1538 void countGenScripts()
1925 {
1926 1538 max_valid_genscript = 0;
1927
2/2
✓ Branch 0 taken 785918 times.
✓ Branch 1 taken 1538 times.
787456 for(auto q = 1; q < NUMSCRIPTSGENERIC; ++q)
1928 {
1929
3/4
✓ Branch 0 taken 785918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 781631 times.
✓ Branch 3 taken 4287 times.
785918 if(genericscripts[q] && genericscripts[q]->valid())
1930 4287 max_valid_genscript = q;
1931 785918 }
1932 1538 }
1933 44493 void timeExitAllGenscript(byte exState)
1934 {
1935
2/2
✓ Branch 0 taken 28706 times.
✓ Branch 1 taken 44493 times.
73199 for(auto q = 1; q <= max_valid_genscript; ++q)
1936 28706 user_genscript::get(q).timeExit(exState);
1937 44493 }
1938 477393 void throwGenScriptEvent(int32_t event)
1939 {
1940
2/2
✓ Branch 0 taken 136426 times.
✓ Branch 1 taken 477393 times.
613819 for(auto q = 1; q <= max_valid_genscript; ++q)
1941 {
1942 136426 user_genscript& scr = user_genscript::get(q);
1943
2/2
✓ Branch 0 taken 76759 times.
✓ Branch 1 taken 59667 times.
136426 if(!scr.doscript()) continue;
1944
2/2
✓ Branch 0 taken 73959 times.
✓ Branch 1 taken 2800 times.
76759 if(!genericscripts[q]->valid()) continue;
1945
2/2
✓ Branch 0 taken 41495 times.
✓ Branch 1 taken 32464 times.
73959 if(!scr.waitevent) continue;
1946
2/2
✓ Branch 0 taken 3068 times.
✓ Branch 1 taken 38427 times.
41495 if(scr.eventstate & (1<<event))
1947 {
1948 3068 auto& data = get_script_engine_data(ScriptType::Generic, q);
1949 3068 data.ref.d[rEXP1] = event*10000;
1950 3068 scr.waitevent = false;
1951
1952 //Run the script!
1953 3068 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
1954 3068 }
1955 41495 }
1956 477393 }
1957
1958 219 void load_genscript(const gamedata& gd)
1959 {
1960
2/2
✓ Branch 0 taken 112128 times.
✓ Branch 1 taken 219 times.
112347 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1961 {
1962 112128 user_genscript& gen = user_genscript::get(q);
1963 112128 gen.clear();
1964 112128 gen.doscript() = gd.gen_doscript.get(q);
1965 112128 gen.exitState = gd.gen_exitState[q];
1966 112128 gen.reloadState = gd.gen_reloadState[q];
1967 112128 gen.eventstate = gd.gen_eventstate[q];
1968 112128 gen.initd = gd.gen_initd[q];
1969 112128 gen.data = gd.gen_data[q];
1970 112128 }
1971 219 }
1972 203 void load_genscript(const zinitdata& zd)
1973 {
1974
2/2
✓ Branch 0 taken 103936 times.
✓ Branch 1 taken 203 times.
104139 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1975 {
1976 103936 user_genscript& gen = user_genscript::get(q);
1977 103936 gen.clear();
1978 103936 gen.doscript() = zd.gen_doscript.get(q);
1979 103936 gen.exitState = zd.gen_exitState[q];
1980 103936 gen.reloadState = zd.gen_reloadState[q];
1981 103936 gen.eventstate = zd.gen_eventstate[q];
1982 103936 gen.initd = zd.gen_initd[q];
1983 103936 gen.data = zd.gen_data[q];
1984 103936 }
1985 203 }
1986
1987 1 void save_genscript(gamedata& gd)
1988 {
1989
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
513 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1990 {
1991 512 user_genscript const& gen = user_genscript::get(q);
1992 512 gd.gen_doscript.set(q, gen.doscript());
1993 512 gd.gen_exitState[q] = gen.exitState;
1994 512 gd.gen_reloadState[q] = gen.reloadState;
1995 512 gd.gen_eventstate[q] = gen.eventstate;
1996 512 gd.gen_initd[q] = gen.initd;
1997 512 gd.gen_data[q] = gen.data;
1998 512 }
1999 1 }
2000
2001 602791090 void FFScript::runGenericPassiveEngine(int32_t scrtm)
2002 {
2003
2/2
✓ Branch 0 taken 19590760 times.
✓ Branch 1 taken 583200330 times.
602791090 if(!max_valid_genscript) return; //No generic scripts in the quest!
2004 19590760 bool init = (scrtm == SCR_TIMING_INIT);
2005
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 19590647 times.
19590760 if(!init)
2006 {
2007
2/2
✓ Branch 0 taken 297552 times.
✓ Branch 1 taken 19293095 times.
19590647 if(genscript_timing != scrtm)
2008 {
2009
2/2
✓ Branch 0 taken 1661258 times.
✓ Branch 1 taken 297552 times.
1958810 while(genscript_timing != scrtm)
2010 1661258 runGenericPassiveEngine(genscript_timing);
2011 297552 }
2012 19590647 }
2013
2/2
✓ Branch 0 taken 265536926 times.
✓ Branch 1 taken 19590760 times.
285127686 for(auto q = 1; q <= max_valid_genscript; ++q)
2014 {
2015 265536926 user_genscript& scr = user_genscript::get(q);
2016
2/2
✓ Branch 0 taken 131923962 times.
✓ Branch 1 taken 133612964 times.
265536926 if(!scr.doscript()) continue;
2017
2/2
✓ Branch 0 taken 3460755 times.
✓ Branch 1 taken 128463207 times.
131923962 if(!genericscripts[q]->valid()) continue;
2018
2/2
✓ Branch 0 taken 75940592 times.
✓ Branch 1 taken 52522615 times.
128463207 if(scr.waitevent) continue;
2019
8/8
✓ Branch 0 taken 52522555 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 42174011 times.
✓ Branch 3 taken 10348544 times.
✓ Branch 4 taken 42173499 times.
✓ Branch 5 taken 512 times.
✓ Branch 6 taken 40035983 times.
✓ Branch 7 taken 2137516 times.
52522615 if(!init && (scr.waituntil > scrtm || (!scr.wait_atleast && scr.waituntil != scrtm)))
2020 50384527 continue;
2021
2022 //Run the script!
2023 2138088 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
2024 2138088 }
2025
4/4
✓ Branch 0 taken 19590647 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 19088614 times.
✓ Branch 3 taken 502033 times.
19590760 if(init || genscript_timing >= SCR_TIMING_END_FRAME)
2026 502146 genscript_timing = SCR_TIMING_START_FRAME;
2027 19088614 else ++genscript_timing;
2028 602791090 }
2029
2030 13758 void FFScript::initZScriptDMapScripts()
2031 {
2032
2/4
✓ Branch 0 taken 13758 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13758 times.
✗ Branch 3 not taken.
13758 scriptEngineDatas[{ScriptType::DMap, 0}] = ScriptEngineData();
2033
2/4
✓ Branch 0 taken 13758 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13758 times.
✗ Branch 3 not taken.
13758 scriptEngineDatas[{ScriptType::ScriptedPassiveSubscreen, 0}] = ScriptEngineData();
2034 13758 }
2035
2036 1383 void FFScript::initZScriptSubscreenScript()
2037 {
2038
2/4
✓ Branch 0 taken 1383 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1383 times.
✗ Branch 3 not taken.
1383 scriptEngineDatas[{ScriptType::EngineSubscreen, 0}] = ScriptEngineData();
2039 1383 }
2040 13693 void FFScript::initZScriptScriptedActiveSubscreen()
2041 {
2042
2/4
✓ Branch 0 taken 13693 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13693 times.
✗ Branch 3 not taken.
13693 scriptEngineDatas[{ScriptType::ScriptedActiveSubscreen, 0}] = ScriptEngineData();
2043 13693 }
2044
2045 3 void FFScript::initZScriptOnMapScript()
2046 {
2047
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 scriptEngineDatas[{ScriptType::OnMap, 0}] = ScriptEngineData();
2048 3 }
2049
2050 2780 void FFScript::initZScriptHeroScripts()
2051 {
2052
2/4
✓ Branch 0 taken 2780 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2780 times.
✗ Branch 3 not taken.
2780 scriptEngineDatas[{ScriptType::Hero, 0}] = ScriptEngineData();
2053 2780 }
2054
2055 2485 void FFScript::initZScriptItemScripts()
2056 {
2057
2/2
✓ Branch 0 taken 636160 times.
✓ Branch 1 taken 2485 times.
638645 for ( int32_t q = 0; q < 256; q++ )
2058 {
2059 636160 auto& data = get_script_engine_data(ScriptType::Item, q);
2060 636160 data.reset();
2061
2/2
✓ Branch 0 taken 636158 times.
✓ Branch 1 taken 2 times.
636160 data.doscript = (itemsbuf[q].flags&item_passive_script) && game->item[q];
2062 636160 }
2063
2064
2/2
✓ Branch 0 taken 636160 times.
✓ Branch 1 taken 2485 times.
638645 for ( int32_t q = -256; q < 0; q++ )
2065 {
2066 636160 auto& data = get_script_engine_data(ScriptType::Item, q);
2067 636160 data.reset();
2068 636160 data.doscript = 0;
2069 636160 }
2070 2485 }
2071
2072 2658892 int get_mouse_state(int index)
2073 {
2074 2658892 int value = 0;
2075
1/2
✓ Branch 0 taken 2658892 times.
✗ Branch 1 not taken.
2658892 if (replay_is_replaying())
2076 {
2077 2658892 value = replay_get_mouse(index);
2078 2658892 }
2079 else if (index == 0)
2080 {
2081 value = script_mouse_x;
2082 }
2083 else if (index == 1)
2084 {
2085 value = script_mouse_y;
2086 }
2087 else if (index == 2)
2088 {
2089 value = script_mouse_z;
2090 }
2091 else if (index == 3)
2092 {
2093 value = script_mouse_b;
2094 }
2095
2096
2/2
✓ Branch 0 taken 2657296 times.
✓ Branch 1 taken 1596 times.
2658892 if (replay_is_recording())
2097 {
2098 1596 replay_set_mouse(index, value);
2099 1596 }
2100
2101 2658892 return value;
2102 }
2103
2104 ///---------------------------------------------//
2105 // Array Helper Functions //
2106 ///---------------------------------------------//
2107
2108 #define ZCARRAY_MAX_SIZE 214748
2109
2110 303070162 size_t ArrayH::getSize(const int32_t ptr)
2111 {
2112 303070162 ArrayManager am(ptr);
2113 303070162 return am.size();
2114 }
2115
2116 //Can't you get the std::string and then check its length?
2117 int32_t ArrayH::strlen(const int32_t ptr)
2118 {
2119 ArrayManager am(ptr);
2120 if (am.invalid() || am.size() == 0)
2121 return -1;
2122
2123 word count;
2124 size_t sz = am.size();
2125 for(count = 0; BC::checkUserArrayIndex(count, sz) == _NoError
2126 && am.get(count) != '\0'; count++);
2127
2128 return count;
2129 }
2130
2131 //Returns values of a zscript array as an std::string.
2132 12210196 void ArrayH::getString(const int32_t ptr, string &str, dword num_chars, dword offset)
2133 {
2134 12210196 ArrayManager am(ptr);
2135
2136
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12210191 times.
12210196 if(am.invalid())
2137 {
2138 5 str.clear();
2139 5 return;
2140 }
2141
2142 12210191 str.clear();
2143 12210191 size_t sz = am.size();
2144
5/6
✓ Branch 0 taken 173077797 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12210191 times.
✓ Branch 3 taken 160867606 times.
✓ Branch 4 taken 12210191 times.
✓ Branch 5 taken 160867606 times.
173077797 for(word i = offset; BC::checkUserArrayIndex(i, sz) == _NoError && am.get(i) != '\0' && num_chars != 0; i++)
2145 {
2146 160867606 int32_t c = am.get(i) / 10000;
2147
1/2
✓ Branch 0 taken 160867606 times.
✗ Branch 1 not taken.
160867606 if(byte(c) != c)
2148 {
2149 Z_scripterrlog("Illegal char value (%d) at position [%d] in string pointer %d\n", c, i, ptr);
2150 Z_scripterrlog("Value of invalid char will overflow.\n");
2151 }
2152 160867606 str += byte(c);
2153 160867606 --num_chars;
2154 160867606 }
2155 12210196 }
2156
2157 //Used for issues where reading the ZScript array floods the console with errors 'Accessing array index [12] size of 12.
2158 //Happens with Quad3D and some other functions, and I have no clue why. -Z ( 28th April, 2019 )
2159 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2160 void ArrayH::getValues2(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset) //a hack -Z
2161 {
2162 ArrayManager am(ptr);
2163
2164 if(am.invalid())
2165 return;
2166
2167 size_t sz = am.size();
2168 for(word i = offset; BC::checkUserArrayIndex(i, sz+1) == _NoError && num_values != 0; i++)
2169 {
2170 arrayPtr[i] = (am.get(i) / 10000);
2171 num_values--;
2172 }
2173 }
2174
2175 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2176 1080 void ArrayH::getValues(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset)
2177 {
2178 1080 ArrayManager am(ptr);
2179
2180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if (am.invalid())
2181 return;
2182 1080 size_t sz = am.size();
2183
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 12960 times.
✓ Branch 2 taken 1080 times.
✓ Branch 3 taken 12960 times.
14040 for(word i = offset; num_values != 0 && BC::checkUserArrayIndex(i, sz) == _NoError; i++)
2184 {
2185 12960 arrayPtr[i] = (am.get(i) / 10000);
2186 12960 num_values--;
2187 12960 }
2188 1080 }
2189
2190 2 void ArrayH::copyValues(const int32_t ptr, const int32_t ptr2)
2191 {
2192 2 ArrayManager am1(ptr), am2(ptr2);
2193
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if(am1.invalid() || am2.invalid())
2194 return;
2195
2196 2 int sz = std::min(am1.size(),am2.size());
2197
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 for (int i = 0; i < sz; i++)
2198 {
2199 4 am1.set(i,am2.get(i));
2200 4 }
2201 2 }
2202 //Get element from array
2203 1358552739 INLINE int32_t ArrayH::getElement(const int32_t ptr, int32_t offset, const bool neg)
2204 {
2205 1358552739 ArrayManager am(ptr,neg);
2206 1358552739 return am.get(offset);
2207 }
2208
2209 //Set element in array
2210 665951738 INLINE void ArrayH::setElement(const int32_t ptr, int32_t offset, const int32_t value, const bool neg)
2211 {
2212 665951738 ArrayManager am(ptr,neg);
2213 665951738 am.set(offset,value);
2214 665951738 }
2215
2216 3240120 int32_t ArrayH::setArray(const int32_t ptr, string const& s2, bool resize)
2217 {
2218 3240120 ArrayManager am(ptr);
2219
2220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3240120 times.
3240120 if (am.invalid())
2221 return _InvalidPointer;
2222
2223 size_t i;
2224
2225
3/4
✓ Branch 0 taken 3240120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3227328 times.
✓ Branch 3 taken 12792 times.
3240120 if(am.can_resize() && resize)
2226 12792 am.resize_min(s2.size()+1);
2227
2228 3240120 size_t sz = am.size();
2229
2/2
✓ Branch 0 taken 43422066 times.
✓ Branch 1 taken 3240051 times.
46662117 for(i = 0; i < s2.size(); i++)
2230 {
2231
2/2
✓ Branch 0 taken 43421997 times.
✓ Branch 1 taken 69 times.
43422066 if(i >= sz)
2232 {
2233 69 am.set(sz-1,'\0');
2234 69 return _Overflow;
2235 }
2236
2237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43421997 times.
43421997 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2238 43421997 am.set(i,s2[i] * 10000);
2239 43421997 }
2240
2241
1/2
✓ Branch 0 taken 3240051 times.
✗ Branch 1 not taken.
3240051 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2242 3240051 am.set(i,'\0');
2243
2244 3240051 return _NoError;
2245 3240120 }
2246
2247 2343653264 ArrayManager::ArrayManager(int32_t ptr, bool neg) : negAccess(neg)
2248 {
2249 2343653264 _invalid = false;
2250 2343653264 internal_array_id = {};
2251 2343653264 legacy_internal_id = 0;
2252
2253
2/2
✓ Branch 0 taken 65503382 times.
✓ Branch 1 taken 2278149882 times.
2343653264 if (ZScriptVersion::gc_arrays())
2254 {
2255
1/2
✓ Branch 0 taken 65503382 times.
✗ Branch 1 not taken.
65503382 if (auto* array = checkArray(ptr))
2256 {
2257
2/2
✓ Branch 0 taken 3194 times.
✓ Branch 1 taken 65500188 times.
65503382 if (array->internal_id.has_value())
2258 {
2259
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3192 times.
3194 if (array->internal_expired)
2260 {
2261 2 current_zasm_extra_context = scripting_get_zasm_register_context_string(array->internal_id->zasm_var);
2262
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 scripting_log_error_with_context("Invalid internal array: the object this array refers to has expired");
2263 2 _invalid = true;
2264 2 return;
2265 }
2266
2267 3192 aptr = nullptr;
2268 3192 internal_array_id = array->internal_id.value();
2269
1/2
✓ Branch 0 taken 3192 times.
✗ Branch 1 not taken.
3192 if (!zasm_array_supports(internal_array_id.zasm_var))
2270 {
2271 scripting_log_error_with_context("Invalid internal array id: {}", internal_array_id.zasm_var);
2272 _invalid = true;
2273 return;
2274 }
2275 3192 }
2276 else
2277 {
2278 65500188 aptr = &array->arr;
2279 }
2280 65503380 }
2281 else
2282 {
2283 aptr = &INVALIDARRAY;
2284 _invalid = true;
2285 }
2286
2287
1/2
✓ Branch 0 taken 65503380 times.
✗ Branch 1 not taken.
65503380 if (_invalid)
2288 scripting_log_error_with_context("Invalid pointer used as array: {}", ptr);
2289 65503380 return;
2290 }
2291
2292 2278149882 ptr /= 10000;
2293
2294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2278149882 times.
2278149882 if(ptr >= INTARR_OFFS)
2295 {
2296 aptr = nullptr;
2297 legacy_internal_id = ptr;
2298 if(legacy_sz_int_arr(ptr) < 0)
2299 _invalid = true;
2300 }
2301
2/2
✓ Branch 0 taken 2278149163 times.
✓ Branch 1 taken 719 times.
2278149882 else if(ptr == 0)
2302 {
2303 719 aptr = &INVALIDARRAY;
2304 719 _invalid = true;
2305 719 }
2306
2/2
✓ Branch 0 taken 2278149102 times.
✓ Branch 1 taken 61 times.
2278149163 else if(ptr < 0) //An object array?
2307 {
2308 61 int32_t objptr = -ptr;
2309 61 auto it = objectRAM.find(objptr);
2310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
61 if(it == objectRAM.end())
2311 {
2312 aptr = &INVALIDARRAY;
2313 _invalid = true;
2314 }
2315 61 else aptr = &(it->second);
2316 61 }
2317
2/2
✓ Branch 0 taken 1824654082 times.
✓ Branch 1 taken 453495020 times.
2278149102 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //Then it's a global
2318 {
2319 1824654082 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
2320
2321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1824654082 times.
1824654082 if(gptr > game->globalRAM.size())
2322 {
2323 aptr = &INVALIDARRAY;
2324 _invalid = true;
2325 }
2326 1824654082 else aptr = &(game->globalRAM[gptr]);
2327 1824654082 }
2328 else
2329 {
2330
1/2
✓ Branch 0 taken 453495020 times.
✗ Branch 1 not taken.
453495020 if(!localRAM[ptr].Valid())
2331 {
2332 aptr = &INVALIDARRAY;
2333 _invalid = true;
2334 }
2335 453495020 else aptr = &(localRAM[ptr]);
2336 }
2337
2/2
✓ Branch 0 taken 2278149163 times.
✓ Branch 1 taken 719 times.
2278149882 if (_invalid)
2338 {
2339 719 scripting_log_error_with_context("Invalid pointer used as array: {}", ptr);
2340 719 }
2341 2343653264 }
2342 319148787 ArrayManager::ArrayManager(int32_t ptr) : ArrayManager(ptr,can_neg_array){}
2343
2344 1692511908 int32_t ArrayManager::get(int32_t indx) const
2345 {
2346
2/2
✓ Branch 0 taken 241 times.
✓ Branch 1 taken 1692511667 times.
1692511908 if(_invalid) return -10000;
2347
2/2
✓ Branch 0 taken 1692510253 times.
✓ Branch 1 taken 1414 times.
1692511667 if(aptr)
2348 {
2349 1692510253 int32_t sz = size();
2350
2/2
✓ Branch 0 taken 633486 times.
✓ Branch 1 taken 1691876767 times.
1692510253 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2351 {
2352
2/2
✓ Branch 0 taken 1691876571 times.
✓ Branch 1 taken 196 times.
1691876767 if(indx < 0)
2353 196 indx += sz; //[-1] becomes [size-1] -Em
2354 1691876767 return (*aptr)[indx];
2355 }
2356 633486 }
2357 else //internal special array
2358 {
2359
1/2
✓ Branch 0 taken 1414 times.
✗ Branch 1 not taken.
1414 if (ZScriptVersion::gc_arrays())
2360 1414 return zasm_array_get(internal_array_id.zasm_var, internal_array_id.ref, indx);
2361
2362 int32_t sz = size();
2363 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2364 {
2365 if(indx < 0)
2366 indx += sz; //[-1] becomes [size-1] -Em
2367 return legacy_get_int_arr(legacy_internal_id, indx);
2368 }
2369 }
2370 633486 return -10000;
2371 1692511908 }
2372
2373 715461434 void ArrayManager::set(int32_t indx, int32_t val)
2374 {
2375
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 715461432 times.
715461434 if(_invalid) return;
2376
2377
2/2
✓ Branch 0 taken 715461076 times.
✓ Branch 1 taken 356 times.
715461432 if(aptr)
2378 {
2379 715461076 int32_t sz = size();
2380
2/2
✓ Branch 0 taken 7298 times.
✓ Branch 1 taken 715453778 times.
715461076 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2381 {
2382
1/2
✓ Branch 0 taken 715453778 times.
✗ Branch 1 not taken.
715453778 if(indx < 0)
2383 indx += sz; //[-1] becomes [size-1] -Em
2384
2/2
✓ Branch 0 taken 715453485 times.
✓ Branch 1 taken 293 times.
715453778 if (aptr->HoldsObjects())
2385 {
2386 293 int id = (*aptr)[indx];
2387 293 script_object_ref_dec(id);
2388 293 }
2389 715453778 (*aptr)[indx] = val;
2390
2/2
✓ Branch 0 taken 715453485 times.
✓ Branch 1 taken 293 times.
715453778 if (aptr->HoldsObjects())
2391 293 script_object_ref_inc(val);
2392 715453778 }
2393 715461076 }
2394 else //internal special array
2395 {
2396
1/2
✓ Branch 0 taken 356 times.
✗ Branch 1 not taken.
356 if (ZScriptVersion::gc_arrays())
2397 {
2398 356 zasm_array_set(internal_array_id.zasm_var, internal_array_id.ref, indx, val);
2399 356 return;
2400 }
2401
2402 int32_t sz = size();
2403 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2404 {
2405 if(indx < 0)
2406 indx += sz; //[-1] becomes [size-1] -Em
2407 legacy_set_int_arr(legacy_internal_id, indx, val);
2408 }
2409 }
2410 715461434 }
2411
2412 2727065846 int32_t ArrayManager::size() const
2413 {
2414
2/2
✓ Branch 0 taken 473 times.
✓ Branch 1 taken 2727065373 times.
2727065846 if(_invalid) return -1;
2415
2/2
✓ Branch 0 taken 2727063953 times.
✓ Branch 1 taken 1420 times.
2727065373 if(aptr)
2416 2727063953 return aptr->Size();
2417 else // Internal special
2418 {
2419
1/2
✓ Branch 0 taken 1420 times.
✗ Branch 1 not taken.
1420 if (ZScriptVersion::gc_arrays())
2420 1420 return zasm_array_size(internal_array_id.zasm_var, internal_array_id.ref);
2421
2422 int32_t sz = legacy_sz_int_arr(legacy_internal_id);
2423 if(sz < 0)
2424 return -1;
2425 return sz;
2426 }
2427 2727065846 }
2428
2429 1153 bool ArrayManager::resize(size_t newsize)
2430 {
2431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1153 times.
1153 if(_invalid) return false;
2432
2/2
✓ Branch 0 taken 1151 times.
✓ Branch 1 taken 2 times.
1153 if(!aptr)
2433 {
2434 2 log_invalid_operation();
2435 2 return false;
2436 }
2437
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1148 times.
1151 if (aptr->HoldsObjects())
2438 {
2439
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (int i = newsize; i < aptr->Size(); i++)
2440 {
2441 3 auto id = (*aptr)[i];
2442 3 script_object_ref_dec(id);
2443 3 }
2444 3 }
2445 1151 aptr->Resize(newsize);
2446 1151 return true;
2447 1153 }
2448
2449 12792 bool ArrayManager::resize_min(size_t newsize)
2450 {
2451
2/2
✓ Branch 0 taken 12500 times.
✓ Branch 1 taken 292 times.
12792 if(size() >= newsize)
2452 12500 return true;
2453 292 return resize(newsize);
2454 12792 }
2455
2456 3800196 bool ArrayManager::can_resize()
2457 {
2458
2/4
✓ Branch 0 taken 3800196 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3800196 times.
✗ Branch 3 not taken.
3800196 if(_invalid || !aptr)
2459 return false;
2460 3800196 return true;
2461 3800196 }
2462
2463 15 bool ArrayManager::push(int32_t val, int indx)
2464 {
2465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(_invalid) return false;
2466
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if(!aptr)
2467 {
2468 log_invalid_operation();
2469 return false;
2470 }
2471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(aptr->Size() == ZCARRAY_MAX_SIZE)
2472 return false;
2473 15 aptr->Push(val,indx);
2474
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
15 if (aptr->HoldsObjects())
2475 3 script_object_ref_inc(val);
2476 15 return true;
2477 15 }
2478
2479 3 int32_t ArrayManager::pop(int indx)
2480 {
2481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(_invalid) return -10000;
2482
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!aptr)
2483 {
2484 log_invalid_operation();
2485 return -10000;
2486 }
2487
2488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (aptr->Empty())
2489 {
2490 scripting_log_error_with_context("Array had nothing to Pop!");
2491 return -10000;
2492 }
2493
2494 3 int32_t val = aptr->Pop(indx);
2495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (aptr->HoldsObjects())
2496 3 script_object_ref_dec(val);
2497 3 return val;
2498 3 }
2499
2500 std::string ArrayManager::asString(std::function<char const*(int32_t)> formatter, const size_t& limit) const
2501 {
2502 if(_invalid) return "{ INVALID ARRAY }";
2503 std::ostringstream oss;
2504 oss << "{ ";
2505 size_t s = size();
2506 bool overflow = limit < s;
2507 if(overflow)
2508 s = limit;
2509
2510 for(auto q = 0; q < s; ++q)
2511 {
2512 oss << formatter(get(q));
2513 if (q + 1 < s)
2514 oss << ", ";
2515 }
2516 if (overflow)
2517 oss << ", ...";
2518 oss << " }";
2519 return oss.str();
2520 }
2521
2522 2 void ArrayManager::log_invalid_operation() const
2523 {
2524
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (internal_array_id.zasm_var)
2525 {
2526 2 current_zasm_extra_context = scripting_get_zasm_register_context_string(internal_array_id.zasm_var);
2527
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 scripting_log_error_with_context("Internal array not valid for this operation");
2528 2 }
2529 else
2530 {
2531 scripting_log_error_with_context("Internal array '{}' not valid for this operation", legacy_internal_id);
2532 }
2533 2 }
2534
2535 // Call only when the underlying engine object is being deleted. This deallocs script data, and
2536 // invalidates any internal array references that may remain.
2537 // Any script type given to this function must also be handled in
2538 // script_array::internal_array_id::matches.
2539 2313535 void FFScript::destroyScriptableObject(ScriptType scriptType, const int32_t UID)
2540 {
2541 2313535 FFCore.deallocateAllScriptOwned(scriptType, UID);
2542 2313535 FFCore.reset_script_engine_data(scriptType, UID);
2543 2313535 expire_internal_script_arrays(scriptType, UID);
2544 2313535 }
2545
2546 35854 void FFScript::destroyScriptableObjectsOfType(ScriptType scriptType)
2547 {
2548 35854 FFCore.deallocateAllScriptOwnedOfType(scriptType);
2549 35854 FFCore.clear_script_engine_data_of_type(scriptType);
2550 35854 expire_internal_script_arrays(scriptType);
2551 35854 }
2552
2553 2495673 void FFScript::deallocateAllScriptOwned(ScriptType scriptType, const int32_t UID)
2554 {
2555 2495673 std::vector<uint32_t> ids_to_clear;
2556
8/14
✓ Branch 0 taken 2495673 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2495673 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2495673 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 52730190 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 50234517 times.
✓ Branch 9 taken 2495673 times.
✓ Branch 10 taken 50234517 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 50234517 times.
✗ Branch 13 not taken.
52730190 for (auto& script_object : script_objects | std::views::values)
2557 {
2558
3/4
✓ Branch 0 taken 50234517 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 50234349 times.
50234517 if (script_object->own_clear(scriptType, UID))
2559 {
2560
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 ids_to_clear.push_back(script_object->id);
2561 168 script_object->owned_type = ScriptType::None;
2562 168 script_object->owned_i = 0;
2563 168 }
2564 }
2565
2566
6/8
✓ Branch 0 taken 2495673 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1003067 times.
✓ Branch 3 taken 1492606 times.
✓ Branch 4 taken 1003067 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 597376 times.
✓ Branch 7 taken 405691 times.
2495673 if (ZScriptVersion::gc() && script_engine_data_exists(scriptType, UID))
2567 {
2568
1/2
✓ Branch 0 taken 597376 times.
✗ Branch 1 not taken.
597376 auto& data = get_script_engine_data(scriptType, UID);
2569
2/2
✓ Branch 0 taken 126 times.
✓ Branch 1 taken 597376 times.
597502 for (uint32_t offset : data.ref.stack_pos_is_object)
2570 {
2571 126 uint32_t id = data.stack[offset];
2572
1/2
✓ Branch 0 taken 126 times.
✗ Branch 1 not taken.
126 ids_to_clear.push_back(id);
2573 }
2574 597376 data.ref.stack_pos_is_object.clear();
2575 597376 }
2576
2577
3/4
✓ Branch 0 taken 2495673 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1003067 times.
✓ Branch 3 taken 1492606 times.
2495673 if (ZScriptVersion::gc())
2578 {
2579
2/2
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 1003067 times.
1003212 for (auto id : ids_to_clear)
2580
1/2
✓ Branch 0 taken 145 times.
✗ Branch 1 not taken.
145 script_object_ref_dec(id);
2581 1003067 }
2582 else
2583 {
2584
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 1492606 times.
1492755 for (auto id : ids_to_clear)
2585
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 delete_script_object(id);
2586 }
2587
2588
3/4
✓ Branch 0 taken 2495673 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 965142 times.
✓ Branch 3 taken 1530531 times.
2495673 if (!ZScriptVersion::gc_arrays())
2589 {
2590
2/2
✓ Branch 0 taken 6267524445 times.
✓ Branch 1 taken 1530531 times.
6269054976 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2591 {
2592
3/4
✓ Branch 0 taken 6267524445 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30496 times.
✓ Branch 3 taken 6267493949 times.
6267524445 if(arrayOwner[i].own_clear(scriptType,UID))
2593
1/2
✓ Branch 0 taken 30496 times.
✗ Branch 1 not taken.
30496 deallocateArray(i);
2594 6267524445 }
2595 1530531 }
2596 2495673 }
2597
2598 135680 void FFScript::deallocateAllScriptOwnedOfType(ScriptType scriptType)
2599 {
2600 135680 std::vector<uint32_t> ids_to_clear;
2601
8/14
✓ Branch 0 taken 135680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 135680 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 135680 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 521980 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 386300 times.
✓ Branch 9 taken 135680 times.
✓ Branch 10 taken 386300 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 386300 times.
✗ Branch 13 not taken.
521980 for (auto& script_object : script_objects | std::views::values)
2602 {
2603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 386300 times.
386300 if (script_object->owned_type == scriptType)
2604 {
2605 ids_to_clear.push_back(script_object->id);
2606 script_object->owned_type = ScriptType::None;
2607 script_object->owned_i = 0;
2608 }
2609 }
2610
2611
3/4
✓ Branch 0 taken 135680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66745 times.
✓ Branch 3 taken 68935 times.
135680 if (ZScriptVersion::gc())
2612 {
2613
2/2
✓ Branch 0 taken 136926644 times.
✓ Branch 1 taken 66745 times.
136993403 for (auto& [key, data] : scriptEngineDatas)
2614 {
2615
2/2
✓ Branch 0 taken 136926630 times.
✓ Branch 1 taken 14 times.
136926644 if (key.first != scriptType)
2616 136926630 continue;
2617
2618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 for (uint32_t offset : data.ref.stack_pos_is_object)
2619 {
2620 uint32_t id = data.stack[offset];
2621 ids_to_clear.push_back(id);
2622 }
2623 14 data.ref.stack_pos_is_object.clear();
2624 }
2625
2626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66745 times.
66745 for (auto id : ids_to_clear)
2627 script_object_ref_dec(id);
2628 66745 }
2629 else
2630 {
2631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68935 times.
68935 for (auto id : ids_to_clear)
2632 delete_script_object(id);
2633 }
2634
2635
3/4
✓ Branch 0 taken 135680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66344 times.
✓ Branch 3 taken 69336 times.
135680 if (!ZScriptVersion::gc_arrays())
2636 {
2637
2/2
✓ Branch 0 taken 283930920 times.
✓ Branch 1 taken 69336 times.
284000256 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2638 {
2639
1/2
✓ Branch 0 taken 283930920 times.
✗ Branch 1 not taken.
283930920 if(arrayOwner[i].owned_type == scriptType)
2640 deallocateArray(i);
2641 283930920 }
2642 69336 }
2643 135680 }
2644
2645 // Only called when resetting the engine. Don't keep anything.
2646 388 void FFScript::deallocateAllScriptOwned()
2647 {
2648 388 script_object_ids_by_type.clear();
2649 388 script_objects.clear();
2650 388 next_script_object_id_freelist.clear();
2651
2652
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 210 times.
388 if (!ZScriptVersion::gc_arrays())
2653 {
2654
2/2
✓ Branch 0 taken 859950 times.
✓ Branch 1 taken 210 times.
860160 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2655 {
2656
2/2
✓ Branch 0 taken 859788 times.
✓ Branch 1 taken 162 times.
859950 if(localRAM[i].Valid())
2657 {
2658 // Unowned arrays are ALSO deallocated!
2659 162 arrayOwner[i].clear();
2660 162 localRAM[i].Clear();
2661 162 }
2662 859950 }
2663 210 }
2664 388 }
2665
2666 694 void FFScript::deallocateAllScriptOwnedCont()
2667 {
2668 694 std::vector<uint32_t> ids_to_clear;
2669
8/14
✓ Branch 0 taken 694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 694 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 694 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3848 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3154 times.
✓ Branch 9 taken 694 times.
✓ Branch 10 taken 3154 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3154 times.
✗ Branch 13 not taken.
3848 for (auto& script_object : script_objects | std::views::values)
2670 {
2671
2/4
✓ Branch 0 taken 3154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3154 times.
3154 if (script_object->own_clear_cont())
2672 {
2673 ids_to_clear.push_back(script_object->id);
2674 script_object->owned_type = ScriptType::None;
2675 script_object->owned_i = 0;
2676 }
2677 }
2678
2679
3/4
✓ Branch 0 taken 694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 391 times.
694 if (ZScriptVersion::gc())
2680 {
2681
2/2
✓ Branch 0 taken 375850 times.
✓ Branch 1 taken 303 times.
752003 for (auto& [key, data] : scriptEngineDatas)
2682 {
2683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 375850 times.
375850 for (uint32_t offset : data.ref.stack_pos_is_object)
2684 {
2685 uint32_t id = data.stack[offset];
2686 ids_to_clear.push_back(id);
2687 }
2688 375850 data.ref.stack_pos_is_object.clear();
2689 }
2690
2691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 303 times.
303 for (auto id : ids_to_clear)
2692 script_object_ref_dec(id);
2693 303 }
2694 else
2695 {
2696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
391 for (auto id : ids_to_clear)
2697 delete_script_object(id);
2698 }
2699
2700
3/4
✓ Branch 0 taken 694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 303 times.
✓ Branch 3 taken 391 times.
694 if (!ZScriptVersion::gc_arrays())
2701 {
2702 //No QR check here- always deallocate on quest exit.
2703
2/2
✓ Branch 0 taken 1601145 times.
✓ Branch 1 taken 391 times.
1601536 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2704 {
2705
3/4
✓ Branch 0 taken 1601145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✓ Branch 3 taken 1597980 times.
1601145 if(localRAM[i].Valid())
2706 {
2707
2/4
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✗ Branch 3 not taken.
3165 if(arrayOwner[i].own_clear_cont())
2708
1/2
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
3165 deallocateArray(i);
2709 3165 }
2710 1601145 }
2711 391 }
2712 694 }
2713
2714 9933550 weapon *checkLWpn(int32_t uid)
2715 {
2716 9933550 return ResolveSprite<weapon>(uid, "lweapon");
2717 }
2718
2719 19351233 weapon *checkEWpn(int32_t uid)
2720 {
2721 19351233 return ResolveSprite<weapon>(uid, "eweapon");
2722 }
2723
2724 29434315 weapon *checkWpn(int32_t uid)
2725 {
2726 29434315 return ResolveSprite<weapon>(uid, "weapon");
2727 }
2728
2729 566 user_file *checkFile(int32_t ref, bool req_file = false, bool skipError = false)
2730 {
2731 566 user_file* file = user_files.check(ref, skipError);
2732
5/6
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 560 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 560 times.
✗ Branch 5 not taken.
566 if (file && req_file && !file->file)
2733 {
2734 if (skipError) return NULL;
2735
2736 scripting_log_error_with_context("Script attempted to reference an invalid file!");
2737 Z_scripterrlog("File with UID = %d does not have an open file connection!\n", ref);
2738 Z_scripterrlog("Use '->Open()' or '->Create()' to hook to a system file.\n");
2739 return NULL;
2740 }
2741 566 return file;
2742 566 }
2743
2744 8474717 user_genscript *checkGenericScr(int32_t ref)
2745 {
2746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8474717 times.
8474717 if (BC::checkBounds(ref, 1, NUMSCRIPTSGENERIC-1) != SH::_NoError)
2747 return NULL;
2748
2749 8474717 return &user_genscript::get(ref);
2750 8474717 }
2751 extern portal mirror_portal;
2752 portal *checkPortal(int32_t ref, bool skiperr = false)
2753 {
2754 if(ref == -1)
2755 return &mirror_portal;
2756
2757 portal* p = (portal*)portals.getByUID(ref);
2758 if(!p)
2759 {
2760 if(!skiperr)
2761 scripting_log_error_with_context("Invalid portal pointer: {}", ref);
2762 return nullptr;
2763 }
2764 return p;
2765 }
2766
2767 savedportal *checkSavedPortal(int32_t ref, bool skiperr = false)
2768 {
2769 savedportal* sp = game->getSavedPortal(ref);
2770 if(!sp)
2771 {
2772 if(!skiperr)
2773 scripting_log_error_with_context("Invalid savedportal pointer: {}", ref);
2774 return nullptr;
2775 }
2776 return sp;
2777 }
2778 int32_t getPortalFromSaved(savedportal* p)
2779 {
2780 if(p == &(game->saved_mirror_portal))
2781 return -1;
2782 portal* prtl = nullptr;
2783 portals.forEach([&](sprite& spr)
2784 {
2785 portal* tmp = (portal*)&spr;
2786 if(p->getUID() == tmp->saved_data)
2787 {
2788 prtl = tmp;
2789 return true;
2790 }
2791 return false;
2792 });
2793 return prtl ? prtl->getUID() : 0;
2794 }
2795
2796 static user_dir *checkDir(uint32_t id, bool skipError = false)
2797 {
2798 return user_dirs.check(id, skipError);
2799 }
2800
2801 static user_stack *checkStack(uint32_t id, bool skipError = false)
2802 {
2803 return user_stacks.check(id, skipError);
2804 }
2805
2806 449481 static user_rng *checkRNG(uint32_t id, bool skipError = false)
2807 {
2808 // A null RNG pointer is special-case, access engine rng.
2809
2/2
✓ Branch 0 taken 447958 times.
✓ Branch 1 taken 1523 times.
449481 if (id == 0) return &nulrng;
2810 1523 return user_rngs.check(id, skipError);
2811 449481 }
2812
2813 17949 user_paldata* checkPalData(int32_t ref, bool skipError)
2814 {
2815 17949 return user_paldatas.check(ref, skipError);
2816 }
2817
2818 42504 newcombo* checkCombo(int32_t ref, bool skipError)
2819 {
2820
2/4
✓ Branch 0 taken 42504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 42504 times.
42504 if (ref < 0 || ref > (MAXCOMBOS-1) )
2821 {
2822 scripting_log_error_with_context("Invalid combodata ID: {}", ref);
2823 return nullptr;
2824 }
2825
2826 42504 return &combobuf[ref];
2827 42504 }
2828
2829 newcombo* checkComboFromTriggerRef(dword ref)
2830 {
2831 ref = get_combo_from_trigger_ref(ref);
2832 return checkCombo(ref);
2833 }
2834
2835 44562 dmap* checkDmap(int32_t ref)
2836 {
2837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
44562 if (BC::checkDMapID(ref) != SH::_NoError)
2838 return nullptr;
2839
2840 44562 return &DMaps[ref];
2841 44562 }
2842
2843 23474086 ffcdata* checkFFC(int32_t ref)
2844 {
2845 23474086 return ResolveFFC(ref);
2846 }
2847
2848 45830930 enemy* checkNPC(int32_t ref)
2849 {
2850 45830930 return ResolveNpc(ref);
2851 }
2852
2853 guydata* checkNPCData(int32_t ref)
2854 {
2855 if (ref >= 0 && ref < MAXNPCS)
2856 return &guysbuf[ref];
2857
2858 scripting_log_error_with_context("Invalid {} using UID = {}", "npcdata", ref);
2859 return nullptr;
2860 }
2861
2862 2239361 item* checkItem(int32_t ref)
2863 {
2864 2239361 return ResolveItemSprite(ref);
2865 }
2866
2867 167 itemdata* checkItemData(int32_t ref)
2868 {
2869
2/4
✓ Branch 0 taken 167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167 times.
✗ Branch 3 not taken.
167 if (ref >= 0 && ref < MAXITEMS)
2870 167 return &itemsbuf[ref];
2871
2872 scripting_log_error_with_context("Invalid {} using UID = {}", "itemdata", ref);
2873 return nullptr;
2874 167 }
2875
2876 88347449 mapdata* checkMapData(int32_t ref)
2877 {
2878 static mapdata last_result;
2879
2880 88347449 last_result = decode_mapdata_ref(ref);
2881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88347449 times.
88347449 if (!last_result.scr)
2882 {
2883 scripting_log_error_with_context("Invalid {} using UID = {}", "mapdata", ref);
2884 return nullptr;
2885 }
2886
2887 88347449 return &last_result;
2888 88347449 }
2889
2890 45474 mapscr* checkMapDataScr(int32_t ref)
2891 {
2892 45474 return decode_mapdata_ref(ref).scr;
2893 }
2894
2895 24924116 screendata* checkScreen(int32_t ref)
2896 {
2897 24924116 return (screendata*)get_scr_maybe(cur_map, ref);
2898 }
2899
2900 bottletype* checkBottleData(int32_t ref, bool skipError)
2901 {
2902 if(ref > 0 && ref <= 64)
2903 {
2904 return &QMisc.bottle_types[ref-1];
2905 }
2906 if(skipError) return NULL;
2907
2908 scripting_log_error_with_context("Invalid {} using UID = {}", "bottledata", ref);
2909 return NULL;
2910 }
2911
2912 bottleshoptype *checkBottleShopData(int32_t ref, bool skipError)
2913 {
2914 if(ref > 0 && ref <= 256)
2915 {
2916 return &QMisc.bottle_shop_types[ref-1];
2917 }
2918 if(skipError) return NULL;
2919
2920 scripting_log_error_with_context("Invalid {} using UID = {}", "bottleshopdata", ref);
2921 return NULL;
2922 }
2923
2924 item_drop_object *checkDropSetData(int32_t ref)
2925 {
2926 if(ref > 0 && ref < MAXITEMDROPSETS)
2927 return &item_drop_sets[ref];
2928
2929 scripting_log_error_with_context("Invalid {} using UID = {}", "dropsetdata", ref);
2930 return NULL;
2931 }
2932
2933 16 wpndata *checkSpriteData(int32_t ref)
2934 {
2935
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 if(ref > 0 && ref < MAXWPNS)
2936 16 return &wpnsbuf[ref];
2937
2938 scripting_log_error_with_context("Invalid {} using UID = {}", "spritedata", ref);
2939 return NULL;
2940 16 }
2941
2942 MsgStr *checkMessageData(int32_t ref)
2943 {
2944 if(ref > 0 && ref < msg_strings_size)
2945 return &MsgStrings[ref];
2946
2947 scripting_log_error_with_context("Invalid {} using UID = {}", "messagedata", ref);
2948 return NULL;
2949 }
2950
2951 combo_trigger* checkComboTrigger(dword ref)
2952 {
2953 return get_combo_trigger(ref);
2954 }
2955
2956 53724680 user_bitmap *checkBitmap(int32_t ref, bool req_valid = false, bool skipError = false)
2957 {
2958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53724680 times.
53724680 switch (ref - 10)
2959 {
2960 case rtSCREEN:
2961 case rtBMP0:
2962 case rtBMP1:
2963 case rtBMP2:
2964 case rtBMP3:
2965 case rtBMP4:
2966 case rtBMP5:
2967 case rtBMP6:
2968 zprint2("Internal error: 'checkBitmap()' recieved ref pointing to system bitmap!\n");
2969 zprint2("Please report this as a bug!\n");
2970
2971 if(skipError) return NULL;
2972
2973 scripting_log_error_with_context("Tried to reference a non-existent bitmap with UID = {}", ref);
2974 return NULL;
2975
2976 default:
2977 {
2978 53724680 user_bitmap* b = user_bitmaps.check(ref, skipError);
2979
4/6
✓ Branch 0 taken 53694494 times.
✓ Branch 1 taken 30186 times.
✓ Branch 2 taken 53694494 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53694494 times.
✗ Branch 5 not taken.
53724680 if (req_valid && (!b || !b->u_bmp))
2980 {
2981 if (skipError) return NULL;
2982
2983 scripting_log_error_with_context("Tried to reference an invalid user bitmap with UID = {}.", ref);
2984 Z_scripterrlog("Did you forget to create the bitmap with `new bitmap()` or `->Create()`?.\n");
2985 return NULL;
2986 }
2987 53724680 return b;
2988 }
2989 }
2990 53724680 }
2991
2992 extern const std::string subscr_names[sstMAX];
2993 159701 ZCSubscreen *checkSubData(int32_t ref, int req_ty)
2994 {
2995 319402 auto [ptr,ty] = load_subdata(ref);
2996
1/2
✓ Branch 0 taken 159701 times.
✗ Branch 1 not taken.
159701 if(ptr)
2997 {
2998
4/6
✓ Branch 0 taken 5097 times.
✓ Branch 1 taken 154604 times.
✓ Branch 2 taken 5097 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5097 times.
✗ Branch 5 not taken.
159701 if(req_ty < 0 || req_ty == ty)
2999 159701 return ptr;
3000 else
3001 {
3002 scripting_log_error_with_context("Wrong type of SubscreenData accessed! Expecting type '{}', but found '{}'",
3003 subscr_names[req_ty], subscr_names[ty]);
3004 }
3005 }
3006 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenData!");
3007
3008 scripting_log_error_with_context("You were trying to reference an invalid SubscreenData with UID = {}", ref);
3009 return NULL;
3010 159701 }
3011
3012 56028 SubscrPage *checkSubPage(int32_t ref, int req_ty)
3013 {
3014 112056 auto [ptr,ty] = load_subpage(ref);
3015
1/2
✓ Branch 0 taken 56028 times.
✗ Branch 1 not taken.
56028 if(ptr)
3016 {
3017
4/6
✓ Branch 0 taken 14870 times.
✓ Branch 1 taken 41158 times.
✓ Branch 2 taken 14870 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14870 times.
✗ Branch 5 not taken.
56028 if(req_ty < 0 || req_ty == ty)
3018 56028 return ptr;
3019 else
3020 {
3021 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting type '{}', but found '{}'",
3022 subscr_names[req_ty], subscr_names[ty]);
3023 }
3024 }
3025 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenPage!");
3026
3027 scripting_log_error_with_context("You were trying to reference an invalid SubscreenPage with UID = {}", ref);
3028 return NULL;
3029 56028 }
3030
3031 103742 SubscrWidget *checkSubWidg(int32_t ref, int req_widg_ty, int req_sub_ty)
3032 {
3033 207484 auto [ptr,ty] = load_subwidg(ref);
3034
1/2
✓ Branch 0 taken 103742 times.
✗ Branch 1 not taken.
103742 if(ptr)
3035 {
3036
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_sub_ty < 0 || req_sub_ty == ty)
3037 {
3038
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_widg_ty < 0 || req_widg_ty == ptr->getType())
3039 103742 return ptr;
3040 else
3041 {
3042 auto listdata = GUI::ZCListData::subscr_widgets();
3043 scripting_log_error_with_context("Wrong type of SubscreenWidget accessed! Expecting type '{}', but found '{}'",
3044 listdata.findText(req_widg_ty), listdata.findText(ptr->getType()));
3045 }
3046 }
3047 else
3048 {
3049 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting subscreen type '{}', but found '{}'",
3050 subscr_names[req_sub_ty], subscr_names[ty]);
3051 }
3052 }
3053 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenWidget!");
3054
3055 scripting_log_error_with_context("You were trying to reference an invalid SubscreenWidget with UID = {}", ref);
3056 return NULL;
3057 103742 }
3058
3059 static void bad_subwidg_type(bool func, byte type)
3060 {
3061 auto tyname = type < widgMAX ? subwidg_internal_names[type].c_str() : "";
3062 scripting_log_error_with_context("Widget type {} '{}' does not have this {}!",
3063 type, tyname, func ? "function" : "value");
3064 }
3065
3066 // TODO: Remove this.
3067 sprite *s;
3068
3069 3 int32_t item_flag(item_flags flag)
3070 {
3071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(unsigned(ri->idata) >= MAXITEMS)
3072 {
3073 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3074 return 0;
3075 }
3076 3 return (itemsbuf[ri->idata].flags & flag) ? 10000 : 0;
3077 3 }
3078 void item_flag(item_flags flag, bool val)
3079 {
3080 if(unsigned(ri->idata) >= MAXITEMS)
3081 {
3082 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3083 return;
3084 }
3085 SETFLAG(itemsbuf[ri->idata].flags, flag, val);
3086 }
3087
3088 bool scripting_use_8bit_colors;
3089 int scripting_max_color_val;
3090
3091 440756 static int scripting_read_pal_color(int c)
3092 {
3093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 440756 times.
440756 return scripting_use_8bit_colors ? c : c / 4;
3094 }
3095
3096 139440 static int scripting_write_pal_color(int c)
3097 {
3098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139440 times.
139440 return scripting_use_8bit_colors ? c : _rgb_scale_6[c];
3099 }
3100
3101 7870 void apply_qr_rule(int qr_id)
3102 {
3103 7870 bool value = get_qr(qr_id);
3104
6/6
✓ Branch 0 taken 2283 times.
✓ Branch 1 taken 1116 times.
✓ Branch 2 taken 1116 times.
✓ Branch 3 taken 1116 times.
✓ Branch 4 taken 1116 times.
✓ Branch 5 taken 1123 times.
7870 switch (qr_id)
3105 {
3106 case qr_LTTPWALK:
3107 1116 Hero.setDiagMove(value?1:0);
3108 1116 break;
3109 case qr_LTTPCOLLISION:
3110 1116 Hero.setBigHitbox(value?1:0);
3111 1116 break;
3112 case qr_ZS_NO_NEG_ARRAY:
3113 1116 can_neg_array = !value;
3114 1116 break;
3115 case qr_SCRIPTS_6_BIT_COLOR:
3116 {
3117
2/2
✓ Branch 0 taken 1115 times.
✓ Branch 1 taken 1 times.
1116 if (value)
3118 {
3119 1115 scripting_use_8bit_colors = false;
3120 1115 scripting_max_color_val = 63;
3121 1115 }
3122 else
3123 {
3124 1 scripting_use_8bit_colors = true;
3125 1 scripting_max_color_val = 255;
3126 }
3127 1116 break;
3128 }
3129 case qr_HIDE_BOTTOM_8_PIXELS:
3130 {
3131 1123 updateShowBottomPixels();
3132 1123 break;
3133 }
3134 }
3135 7870 }
3136
3137 1116 static void apply_qr_rules()
3138 {
3139 1116 apply_qr_rule(qr_HIDE_BOTTOM_8_PIXELS);
3140 1116 apply_qr_rule(qr_LTTPCOLLISION);
3141 1116 apply_qr_rule(qr_LTTPWALK);
3142 1116 apply_qr_rule(qr_SCRIPTS_6_BIT_COLOR);
3143 1116 apply_qr_rule(qr_ZS_NO_NEG_ARRAY);
3144 1116 }
3145
3146 //Forward decl
3147 int32_t do_msgheight(int32_t msg);
3148 int32_t do_msgwidth(int32_t msg);
3149 //
3150
3151 template <typename T, size_t N>
3152 static int read_array(const T(&arr)[N], int index)
3153 {
3154 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
3155 return 0;
3156
3157 return arr[index];
3158 }
3159
3160 template <typename T, size_t N>
3161 static bool write_array(T(&arr)[N], int index, T value)
3162 {
3163 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
3164 return false;
3165
3166 arr[index] = value;
3167 return true;
3168 }
3169
3170 227698154 static int get_ref(int arg)
3171 {
3172
15/26
✗ Branch 0 not taken.
✓ Branch 1 taken 2206362 times.
✓ Branch 2 taken 88302904 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2475 times.
✓ Branch 5 taken 102 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 42504 times.
✓ Branch 10 taken 44517 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27227949 times.
✓ Branch 13 taken 23474086 times.
✓ Branch 14 taken 8469039 times.
✓ Branch 15 taken 169465 times.
✓ Branch 16 taken 167 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 45830930 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 27524974 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 4352700 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 49980 times.
✗ Branch 25 not taken.
227698154 switch (arg)
3173 {
3174 case REFBITMAP: return ri->bitmapref;
3175 case REFBOTTLESHOP: return ri->bottleshopref;
3176 case REFBOTTLETYPE: return ri->bottletyperef;
3177 42504 case REFCOMBODATA: return ri->combosref;
3178 case REFCOMBOTRIGGER: return ri->combotrigref;
3179 44517 case REFDMAPDATA: return ri->dmapsref;
3180 case REFDROPS: return ri->dropsetref;
3181 27227949 case REFEWPN: return ri->ewpn;
3182 23474086 case REFFFC: return ri->ffcref;
3183 8469039 case REFGENERICDATA: return ri->genericdataref;
3184 169465 case REFITEM: return ri->itemref;
3185 167 case REFITEMCLASS: return ri->idata;
3186 2206362 case REFLWPN: return ri->lwpn;
3187 88302904 case REFMAPDATA: return ri->mapsref;
3188 case REFMSGDATA: return ri->zmsgref;
3189 45830930 case REFNPC: return ri->guyref;
3190 case REFNPCCLASS: return ri->npcdataref;
3191 case REFPALDATA: return ri->paldataref;
3192 27524974 case REFSCREENDATA: return ri->screenref;
3193 case REFSHOPDATA: return ri->shopsref;
3194 4352700 case REFSPRITE: return ri->spriteref;
3195 case REFSPRITEDATA: return ri->spritedataref;
3196 49980 case REFSUBSCREEN: return ri->subdataref;
3197 2475 case REFSUBSCREENPAGE: return ri->subpageref;
3198 102 case REFSUBSCREENWIDG: return ri->subwidgref;
3199
3200 default: NOTREACHED();
3201 }
3202 227698154 }
3203
3204 int32_t earlyretval = -1;
3205 7365563285 int32_t get_register(int32_t arg)
3206 {
3207
3/4
✓ Branch 0 taken 7365563285 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3146375918 times.
✓ Branch 3 taken 4219187367 times.
7365563285 if (arg >= D(0) && arg <= D(7))
3208 4219187367 return ri->d[arg - D(0)];
3209
3210
4/4
✓ Branch 0 taken 2598371479 times.
✓ Branch 1 taken 548004439 times.
✓ Branch 2 taken 2370296570 times.
✓ Branch 3 taken 228074909 times.
3146375918 if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
3211 228074909 return game->global_d[arg - GD(0)];
3212
3213 2918301009 int32_t ret = 0;
3214
3215 #define GET_SPRITEDATA_VAR_INT(member) \
3216 { \
3217 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
3218 { \
3219 ret = -10000; \
3220 scripting_log_error_with_context("Invalid Sprite ID: {}", ri->spritedataref*10000); \
3221 } \
3222 else \
3223 ret = (wpnsbuf[ri->spritedataref].member * 10000); \
3224 }
3225
3226 2918301009 current_zasm_register = arg;
3227
3228 // Do not ever use `return` in these cases!
3229
282/1051
✗ Branch 0 not taken.
✓ Branch 1 taken 296970 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1125663338 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 632522657 times.
✓ Branch 9 taken 3175238 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 623627 times.
✓ Branch 12 taken 13052070 times.
✓ Branch 13 taken 531424995 times.
✓ Branch 14 taken 2312685 times.
✓ Branch 15 taken 10 times.
✓ Branch 16 taken 24185365 times.
✓ Branch 17 taken 23746245 times.
✓ Branch 18 taken 5823964 times.
✓ Branch 19 taken 163102 times.
✓ Branch 20 taken 377 times.
✓ Branch 21 taken 51 times.
✓ Branch 22 taken 51 times.
✓ Branch 23 taken 204076 times.
✓ Branch 24 taken 199035 times.
✓ Branch 25 taken 5283857 times.
✓ Branch 26 taken 5194596 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 41781165 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 42668363 times.
✓ Branch 32 taken 4020681 times.
✓ Branch 33 taken 719568 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 9094315 times.
✓ Branch 36 taken 441276 times.
✓ Branch 37 taken 24133559 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 2790134 times.
✓ Branch 41 taken 1061313 times.
✓ Branch 42 taken 944827 times.
✓ Branch 43 taken 78367320 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 204 times.
✓ Branch 46 taken 5424 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 1249005 times.
✓ Branch 49 taken 573955 times.
✓ Branch 50 taken 652486 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✓ Branch 54 taken 959935 times.
✓ Branch 55 taken 1095514 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 656387 times.
✓ Branch 60 taken 571655 times.
✓ Branch 61 taken 113145 times.
✓ Branch 62 taken 115547 times.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✓ Branch 67 taken 489104 times.
✓ Branch 68 taken 489104 times.
✓ Branch 69 taken 288295 times.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 4101 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 57322 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 180367 times.
✓ Branch 80 taken 440770 times.
✓ Branch 81 taken 2 times.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✓ Branch 84 taken 428588 times.
✓ Branch 85 taken 432590 times.
✓ Branch 86 taken 337110 times.
✓ Branch 87 taken 273630 times.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 271788 times.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✓ Branch 95 taken 832354 times.
✓ Branch 96 taken 18 times.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✓ Branch 99 taken 4357 times.
✗ Branch 100 not taken.
✓ Branch 101 taken 1012 times.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✓ Branch 119 taken 136185 times.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✓ Branch 128 taken 92967 times.
✓ Branch 129 taken 4123 times.
✓ Branch 130 taken 4321356 times.
✓ Branch 131 taken 3824036 times.
✓ Branch 132 taken 4211785 times.
✓ Branch 133 taken 4388042 times.
✓ Branch 134 taken 6701954 times.
✓ Branch 135 taken 5699839 times.
✓ Branch 136 taken 3218568 times.
✓ Branch 137 taken 3214309 times.
✓ Branch 138 taken 120159 times.
✓ Branch 139 taken 120450 times.
✓ Branch 140 taken 23391 times.
✓ Branch 141 taken 23391 times.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✓ Branch 146 taken 791031 times.
✓ Branch 147 taken 791031 times.
✗ Branch 148 not taken.
✓ Branch 149 taken 1073638 times.
✓ Branch 150 taken 818518 times.
✓ Branch 151 taken 335732 times.
✓ Branch 152 taken 1118025 times.
✓ Branch 153 taken 1056398 times.
✓ Branch 154 taken 963357 times.
✓ Branch 155 taken 870340 times.
✓ Branch 156 taken 2442823 times.
✓ Branch 157 taken 1811399 times.
✓ Branch 158 taken 2061226 times.
✓ Branch 159 taken 1845780 times.
✓ Branch 160 taken 1237553 times.
✓ Branch 161 taken 1081361 times.
✓ Branch 162 taken 558264 times.
✓ Branch 163 taken 669416 times.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✓ Branch 195 taken 53 times.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✓ Branch 201 taken 5960535 times.
✓ Branch 202 taken 16858 times.
✓ Branch 203 taken 3 times.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✓ Branch 218 taken 1994 times.
✓ Branch 219 taken 1914 times.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✓ Branch 233 taken 55670 times.
✗ Branch 234 not taken.
✓ Branch 235 taken 55645 times.
✗ Branch 236 not taken.
✓ Branch 237 taken 63041 times.
✓ Branch 238 taken 142873 times.
✓ Branch 239 taken 74538 times.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✓ Branch 251 taken 954757 times.
✗ Branch 252 not taken.
✓ Branch 253 taken 950150 times.
✓ Branch 254 taken 109736 times.
✓ Branch 255 taken 6 times.
✗ Branch 256 not taken.
✓ Branch 257 taken 80933 times.
✗ Branch 258 not taken.
✓ Branch 259 taken 5388 times.
✓ Branch 260 taken 416 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 246 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 6 times.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✓ Branch 267 taken 6 times.
✓ Branch 268 taken 103896 times.
✓ Branch 269 taken 7611 times.
✓ Branch 270 taken 4109108 times.
✓ Branch 271 taken 53697 times.
✓ Branch 272 taken 586 times.
✗ Branch 273 not taken.
✓ Branch 274 taken 53381 times.
✓ Branch 275 taken 220 times.
✓ Branch 276 taken 4362 times.
✓ Branch 277 taken 6 times.
✓ Branch 278 taken 4362 times.
✓ Branch 279 taken 6 times.
✗ Branch 280 not taken.
✓ Branch 281 taken 1950927 times.
✓ Branch 282 taken 6 times.
✓ Branch 283 taken 835937 times.
✓ Branch 284 taken 23909 times.
✓ Branch 285 taken 299718 times.
✓ Branch 286 taken 10231 times.
✓ Branch 287 taken 11477 times.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✓ Branch 291 taken 6 times.
✓ Branch 292 taken 283042 times.
✓ Branch 293 taken 284996 times.
✓ Branch 294 taken 36540 times.
✓ Branch 295 taken 32019 times.
✓ Branch 296 taken 32019 times.
✓ Branch 297 taken 5455 times.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✓ Branch 301 taken 3 times.
✓ Branch 302 taken 60075 times.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✓ Branch 306 taken 1552 times.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✓ Branch 311 taken 48553 times.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✓ Branch 326 taken 4354386 times.
✗ Branch 327 not taken.
✓ Branch 328 taken 4354484 times.
✓ Branch 329 taken 552907 times.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✓ Branch 332 taken 61563 times.
✓ Branch 333 taken 2845 times.
✗ Branch 334 not taken.
✓ Branch 335 taken 610345 times.
✓ Branch 336 taken 718383 times.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✓ Branch 340 taken 136793 times.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✓ Branch 343 taken 46359 times.
✓ Branch 344 taken 90304 times.
✓ Branch 345 taken 6052 times.
✓ Branch 346 taken 2800078 times.
✓ Branch 347 taken 205013 times.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✓ Branch 350 taken 65315 times.
✗ Branch 351 not taken.
✓ Branch 352 taken 96 times.
✗ Branch 353 not taken.
✓ Branch 354 taken 96 times.
✗ Branch 355 not taken.
✓ Branch 356 taken 12006 times.
✓ Branch 357 taken 218 times.
✓ Branch 358 taken 6012426 times.
✗ Branch 359 not taken.
✓ Branch 360 taken 10477 times.
✗ Branch 361 not taken.
✓ Branch 362 taken 157773 times.
✓ Branch 363 taken 157773 times.
✓ Branch 364 taken 48464 times.
✓ Branch 365 taken 60558 times.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✓ Branch 369 taken 1880 times.
✓ Branch 370 taken 149564 times.
✓ Branch 371 taken 149564 times.
✓ Branch 372 taken 81355 times.
✓ Branch 373 taken 125257 times.
✓ Branch 374 taken 125257 times.
✓ Branch 375 taken 10565 times.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✓ Branch 380 taken 43 times.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✓ Branch 386 taken 30735 times.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✓ Branch 402 taken 792465 times.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✓ Branch 406 taken 225 times.
✓ Branch 407 taken 63717 times.
✓ Branch 408 taken 11271214 times.
✓ Branch 409 taken 96 times.
✗ Branch 410 not taken.
✓ Branch 411 taken 58184250 times.
✓ Branch 412 taken 15080301 times.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✓ Branch 416 taken 47264 times.
✓ Branch 417 taken 39568 times.
✓ Branch 418 taken 64 times.
✓ Branch 419 taken 20 times.
✓ Branch 420 taken 32 times.
✓ Branch 421 taken 982758 times.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✓ Branch 425 taken 24940 times.
✓ Branch 426 taken 21112 times.
✓ Branch 427 taken 8014 times.
✓ Branch 428 taken 11842 times.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✓ Branch 441 taken 1026 times.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 467 not taken.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✓ Branch 471 taken 17 times.
✗ Branch 472 not taken.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✓ Branch 475 taken 910 times.
✗ Branch 476 not taken.
✗ Branch 477 not taken.
✓ Branch 478 taken 9492 times.
✓ Branch 479 taken 43250 times.
✗ Branch 480 not taken.
✓ Branch 481 taken 6 times.
✗ Branch 482 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✓ Branch 487 taken 10246 times.
✓ Branch 488 taken 7214 times.
✓ Branch 489 taken 2391 times.
✓ Branch 490 taken 25369944 times.
✓ Branch 491 taken 47 times.
✓ Branch 492 taken 2 times.
✓ Branch 493 taken 343159 times.
✓ Branch 494 taken 100950 times.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✗ Branch 497 not taken.
✓ Branch 498 taken 1636 times.
✓ Branch 499 taken 1610 times.
✓ Branch 500 taken 32 times.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✓ Branch 504 taken 16 times.
✗ Branch 505 not taken.
✓ Branch 506 taken 16 times.
✗ Branch 507 not taken.
✓ Branch 508 taken 16 times.
✓ Branch 509 taken 16 times.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✓ Branch 512 taken 6567172 times.
✓ Branch 513 taken 3858 times.
✓ Branch 514 taken 192 times.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✓ Branch 527 taken 192 times.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✓ Branch 550 taken 32 times.
✓ Branch 551 taken 2004 times.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✓ Branch 561 taken 9 times.
✓ Branch 562 taken 21 times.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✓ Branch 567 taken 701 times.
✓ Branch 568 taken 225 times.
✗ Branch 569 not taken.
✓ Branch 570 taken 6 times.
✗ Branch 571 not taken.
✓ Branch 572 taken 212 times.
✓ Branch 573 taken 19 times.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✓ Branch 576 taken 1124 times.
✓ Branch 577 taken 1095768 times.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✓ Branch 580 taken 5120 times.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✓ Branch 590 taken 22016 times.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✓ Branch 616 taken 60340 times.
✓ Branch 617 taken 12211 times.
✓ Branch 618 taken 208371 times.
✓ Branch 619 taken 19038 times.
✓ Branch 620 taken 116988 times.
✓ Branch 621 taken 112420 times.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✓ Branch 625 taken 4546 times.
✓ Branch 626 taken 6890 times.
✓ Branch 627 taken 755 times.
✓ Branch 628 taken 5110 times.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✓ Branch 632 taken 463074 times.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✓ Branch 641 taken 18 times.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✓ Branch 657 taken 25 times.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✓ Branch 698 taken 11602 times.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 707 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✗ Branch 719 not taken.
✗ Branch 720 not taken.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✗ Branch 724 not taken.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✓ Branch 832 taken 3182 times.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✓ Branch 837 taken 3182 times.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✓ Branch 853 taken 1 times.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✓ Branch 876 taken 10 times.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✓ Branch 880 taken 3453 times.
✗ Branch 881 not taken.
✗ Branch 882 not taken.
✗ Branch 883 not taken.
✗ Branch 884 not taken.
✗ Branch 885 not taken.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✓ Branch 888 taken 26654 times.
✓ Branch 889 taken 608463 times.
✓ Branch 890 taken 5613429 times.
✓ Branch 891 taken 1561195 times.
✓ Branch 892 taken 4923551 times.
✓ Branch 893 taken 27873688 times.
✗ Branch 894 not taken.
✗ Branch 895 not taken.
✓ Branch 896 taken 20 times.
✓ Branch 897 taken 215684 times.
✗ Branch 898 not taken.
✓ Branch 899 taken 16 times.
✓ Branch 900 taken 10 times.
✓ Branch 901 taken 1 times.
✓ Branch 902 taken 72930 times.
✗ Branch 903 not taken.
✓ Branch 904 taken 24 times.
✓ Branch 905 taken 10 times.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✓ Branch 908 taken 137715 times.
✗ Branch 909 not taken.
✗ Branch 910 not taken.
✗ Branch 911 not taken.
✓ Branch 912 taken 36 times.
✗ Branch 913 not taken.
✗ Branch 914 not taken.
✗ Branch 915 not taken.
✗ Branch 916 not taken.
✓ Branch 917 taken 6314 times.
✓ Branch 918 taken 1119 times.
✗ Branch 919 not taken.
✓ Branch 920 taken 8 times.
✓ Branch 921 taken 70504508 times.
✗ Branch 922 not taken.
✓ Branch 923 taken 1573532 times.
✗ Branch 924 not taken.
✓ Branch 925 taken 5519 times.
✗ Branch 926 not taken.
✗ Branch 927 not taken.
✗ Branch 928 not taken.
✗ Branch 929 not taken.
✗ Branch 930 not taken.
✗ Branch 931 not taken.
✗ Branch 932 not taken.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✗ Branch 946 not taken.
✗ Branch 947 not taken.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✗ Branch 951 not taken.
✗ Branch 952 not taken.
✗ Branch 953 not taken.
✗ Branch 954 not taken.
✓ Branch 955 taken 14124 times.
✗ Branch 956 not taken.
✗ Branch 957 not taken.
✗ Branch 958 not taken.
✓ Branch 959 taken 54674 times.
✓ Branch 960 taken 11 times.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✗ Branch 963 not taken.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✗ Branch 966 not taken.
✗ Branch 967 not taken.
✗ Branch 968 not taken.
✗ Branch 969 not taken.
✗ Branch 970 not taken.
✗ Branch 971 not taken.
✓ Branch 972 taken 5031 times.
✗ Branch 973 not taken.
✗ Branch 974 not taken.
✗ Branch 975 not taken.
✓ Branch 976 taken 1005 times.
✗ Branch 977 not taken.
✓ Branch 978 taken 17326 times.
✓ Branch 979 taken 6024 times.
✗ Branch 980 not taken.
✓ Branch 981 taken 4206 times.
✓ Branch 982 taken 9836 times.
✗ Branch 983 not taken.
✗ Branch 984 not taken.
✓ Branch 985 taken 339 times.
✓ Branch 986 taken 339 times.
✗ Branch 987 not taken.
✗ Branch 988 not taken.
✗ Branch 989 not taken.
✗ Branch 990 not taken.
✗ Branch 991 not taken.
✗ Branch 992 not taken.
✗ Branch 993 not taken.
✗ Branch 994 not taken.
✗ Branch 995 not taken.
✗ Branch 996 not taken.
✗ Branch 997 not taken.
✗ Branch 998 not taken.
✗ Branch 999 not taken.
✗ Branch 1000 not taken.
✗ Branch 1001 not taken.
✗ Branch 1002 not taken.
✗ Branch 1003 not taken.
✗ Branch 1004 not taken.
✗ Branch 1005 not taken.
✗ Branch 1006 not taken.
✗ Branch 1007 not taken.
✗ Branch 1008 not taken.
✗ Branch 1009 not taken.
✗ Branch 1010 not taken.
✗ Branch 1011 not taken.
✗ Branch 1012 not taken.
✗ Branch 1013 not taken.
✗ Branch 1014 not taken.
✗ Branch 1015 not taken.
✗ Branch 1016 not taken.
✗ Branch 1017 not taken.
✗ Branch 1018 not taken.
✗ Branch 1019 not taken.
✗ Branch 1020 not taken.
✗ Branch 1021 not taken.
✗ Branch 1022 not taken.
✗ Branch 1023 not taken.
✗ Branch 1024 not taken.
✗ Branch 1025 not taken.
✗ Branch 1026 not taken.
✗ Branch 1027 not taken.
✗ Branch 1028 not taken.
✓ Branch 1029 taken 1455 times.
✗ Branch 1030 not taken.
✗ Branch 1031 not taken.
✗ Branch 1032 not taken.
✗ Branch 1033 not taken.
✗ Branch 1034 not taken.
✗ Branch 1035 not taken.
✗ Branch 1036 not taken.
✗ Branch 1037 not taken.
✗ Branch 1038 not taken.
✗ Branch 1039 not taken.
✗ Branch 1040 not taken.
✗ Branch 1041 not taken.
✗ Branch 1042 not taken.
✗ Branch 1043 not taken.
✗ Branch 1044 not taken.
✗ Branch 1045 not taken.
✗ Branch 1046 not taken.
✗ Branch 1047 not taken.
✗ Branch 1048 not taken.
✗ Branch 1049 not taken.
✗ Branch 1050 not taken.
2918301009 switch(arg)
3230 {
3231 case MAX_FFC_ID:
3232 {
3233 3175238 ret = (MAX_FFCID + 1) * 10000;
3234 3175238 break;
3235 }
3236
3237 case INCQST:
3238 {
3239 int32_t newqst = 0;
3240 if ( game->get_quest() < 255 ) //255 is a custom quest
3241 {
3242 newqst = (game->get_quest()+1);
3243 }
3244 else
3245 {
3246 newqst = 1;
3247 }
3248 if ( newqst < 11 )
3249 {
3250
3251 ret = newqst * 10000;
3252 Quit = qINCQST;
3253 //ending();
3254
3255 }
3256 else ret = -10000;
3257 break;
3258 }
3259 case DEBUGTESTING:
3260 623627 ret = use_testingst_start ? 10000 : 0;
3261 623627 break;
3262
3263 ///----------------------------------------------------------------------------------------------------//
3264 //FFC Variables
3265 case DATA:
3266
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13052068 times.
13052070 if (auto ffc = ResolveFFC(ri->ffcref))
3267 13052068 ret = ffc->data * 10000;
3268 13052070 break;
3269
3270 case FFSCRIPT:
3271
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 531424783 times.
531424995 if(auto ffc = ResolveFFC(ri->ffcref))
3272 531424783 ret = ffc->script * 10000;
3273 531424995 break;
3274
3275 case FCSET:
3276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2312685 times.
2312685 if(auto ffc = ResolveFFC(ri->ffcref))
3277 2312685 ret = ffc->cset * 10000;
3278 2312685 break;
3279
3280 case DELAY:
3281
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(auto ffc = ResolveFFC(ri->ffcref))
3282 10 ret = ffc->delay * 10000;
3283 10 break;
3284
3285 case FX:
3286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24185365 times.
24185365 if(auto ffc = ResolveFFC(ri->ffcref))
3287 24185365 ret = ffc->x.getZLong();
3288 24185365 break;
3289
3290 case FY:
3291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23746245 times.
23746245 if(auto ffc = ResolveFFC(ri->ffcref))
3292 23746245 ret = ffc->y.getZLong();
3293 23746245 break;
3294
3295 case XD:
3296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5823964 times.
5823964 if(auto ffc = ResolveFFC(ri->ffcref))
3297 5823964 ret = ffc->vx.getZLong();
3298 5823964 break;
3299
3300 case YD:
3301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 163102 times.
163102 if(auto ffc = ResolveFFC(ri->ffcref))
3302 163102 ret = ffc->vy.getZLong();
3303 163102 break;
3304 case FFCID:
3305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 377 times.
377 if (auto ffc = ResolveFFC(ri->ffcref))
3306 377 ret = (get_region_screen_offset(ffc->screen_spawned) * MAXFFCS + ffc->index + 1) * 10000;
3307 377 break;
3308
3309 case XD2:
3310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(auto ffc = ResolveFFC(ri->ffcref))
3311 51 ret = ffc->ax.getZLong();
3312 51 break;
3313
3314 case YD2:
3315
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto ffc = ResolveFFC(ri->ffcref))
3316 51 ret = ffc->ay.getZLong();
3317 51 break;
3318
3319 case FFCWIDTH:
3320
1/2
✓ Branch 0 taken 204076 times.
✗ Branch 1 not taken.
204076 if(auto ffc = ResolveFFC(ri->ffcref))
3321 204076 ret = ffc->hit_width * 10000;
3322 204076 break;
3323
3324 case FFCHEIGHT:
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199035 times.
199035 if(auto ffc = ResolveFFC(ri->ffcref))
3326 199035 ret = ffc->hit_height * 10000;
3327 199035 break;
3328
3329 case FFTWIDTH:
3330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5283857 times.
5283857 if(auto ffc = ResolveFFC(ri->ffcref))
3331 5283857 ret = ffc->txsz * 10000;
3332 5283857 break;
3333
3334 case FFTHEIGHT:
3335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5194596 times.
5194596 if(auto ffc = ResolveFFC(ri->ffcref))
3336 5194596 ret = ffc->tysz * 10000;
3337 5194596 break;
3338
3339 case FFCLAYER:
3340 if (auto ffc = ResolveFFC(ri->ffcref))
3341 ret = ffc->layer * 10000;
3342 break;
3343
3344 case FFLINK:
3345 if(auto ffc = ResolveFFC(ri->ffcref))
3346 ret = ffc->link * 10000;
3347 break;
3348
3349 ///----------------------------------------------------------------------------------------------------//
3350 //Hero's Variables
3351 case LINKX:
3352 {
3353
2/2
✓ Branch 0 taken 8938966 times.
✓ Branch 1 taken 32842199 times.
41781165 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3354 {
3355 8938966 ret = Hero.getX().getZLong();
3356 8938966 }
3357 32842199 else ret = int32_t(Hero.getX()) * 10000;
3358
3359 41781165 break;
3360 }
3361
3362 case LINKCSET:
3363 {
3364 ret = Hero.cs * 10000;
3365 break;
3366 }
3367 case LINKY:
3368 {
3369
2/2
✓ Branch 0 taken 9752728 times.
✓ Branch 1 taken 32915635 times.
42668363 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3370 {
3371 9752728 ret = Hero.getY().getZLong();
3372 9752728 }
3373 32915635 else ret = int32_t(Hero.getY()) * 10000;
3374
3375 42668363 break;
3376 }
3377 case LINKZ:
3378 {
3379
2/2
✓ Branch 0 taken 2847194 times.
✓ Branch 1 taken 1173487 times.
4020681 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3380 {
3381 2847194 ret = Hero.getZ().getZLong();
3382 2847194 }
3383 1173487 else ret = int32_t(Hero.getZ()) * 10000;
3384
3385 4020681 break;
3386 }
3387 case LINKJUMP:
3388 719568 ret = Hero.getJump().getZLong();
3389 719568 break;
3390
3391 case HEROFAKEJUMP:
3392 ret = Hero.getFakeJump().getZLong() / -100;
3393 break;
3394
3395 case LINKDIR:
3396 9094315 ret=(int32_t)(Hero.dir)*10000;
3397 9094315 break;
3398
3399 case LINKHITDIR:
3400 441276 ret=(int32_t)(Hero.getHitDir())*10000;
3401 441276 break;
3402
3403 case LINKHP:
3404 24133559 ret=(int32_t)(game->get_life())*10000;
3405 24133559 break;
3406
3407 case LINKGRAVITY:
3408 ret = ( (Hero.moveflags & move_obeys_grav) ? 10000 : 0 );
3409 break;
3410
3411 case HERONOSTEPFORWARD:
3412 ret = ( (FFCore.nostepforward) ? 10000 : 0 );
3413 break;
3414
3415 case LINKMP:
3416 2790134 ret=(int32_t)(game->get_magic())*10000;
3417 2790134 break;
3418
3419 case LINKMAXHP:
3420 1061313 ret=(int32_t)(game->get_maxlife())*10000;
3421 1061313 break;
3422
3423 case LINKMAXMP:
3424 944827 ret=(int32_t)(game->get_maxmagic())*10000;
3425 944827 break;
3426
3427 case LINKACTION:
3428 {
3429 78367320 ret = FFCore.getHeroAction() * 10000;
3430 78367320 break;
3431 }
3432
3433 case HEROHEALTHBEEP:
3434 {
3435 ret = heart_beep ? ( heart_beep_timer * 10000 ) : 0;
3436 break;
3437 }
3438
3439 case LINKHELD:
3440 204 ret = (int32_t)(Hero.getHeldItem())*10000;
3441 204 break;
3442
3443 case HEROSTEPRATE:
3444 5424 ret = Hero.getStepRate() * 10000;
3445 5424 break;
3446 case HEROSHOVEOFFSET:
3447 ret = Hero.shove_offset.getZLong();
3448 break;
3449
3450 case LINKEQUIP:
3451 1249005 ret = ((Awpn&0xFF)|((Bwpn&0xFF)<<8))*10000;
3452 1249005 break;
3453
3454 case LINKINVIS:
3455 573955 ret = (((int32_t)(Hero.getDontDraw())) ? 10000 : 0);
3456 573955 break;
3457
3458 case LINKINVINC:
3459 652486 ret = (int32_t)(Hero.scriptcoldet)*10000;
3460 652486 break;
3461
3462 case LINKENGINEANIMATE:
3463 ret = (int32_t)(Hero.do_animation)*10000;
3464 break;
3465
3466 case LINKLADDERX:
3467 ret=(int32_t)(Hero.getLadderX())*10000;
3468 break;
3469
3470 case LINKLADDERY:
3471 ret=(int32_t)(Hero.getLadderY())*10000;
3472 break;
3473
3474 case LINKSWORDJINX:
3475 959935 ret = (int32_t)(Hero.getSwordClk())*10000;
3476 959935 break;
3477
3478 case LINKITEMJINX:
3479 1095514 ret = (int32_t)(Hero.getItemClk())*10000;
3480 1095514 break;
3481
3482 case LINKDRUNK:
3483 ret = (int32_t)(Hero.DrunkClock())*10000;
3484 break;
3485
3486 case LINKROTATION:
3487 if ( get_qr(qr_OLDSPRITEDRAWS) )
3488 {
3489 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3490 ret = -1; break;
3491 }
3492 ret = (int32_t)(Hero.rotation)*10000;
3493 break;
3494
3495 case LINKSCALE:
3496 {
3497 if ( get_qr(qr_OLDSPRITEDRAWS) )
3498 {
3499 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3500 ret = -1; break;
3501 }
3502 ret = (int32_t)(Hero.scale*100.0);
3503 break;
3504 }
3505
3506
3507 case LINKHXOFS:
3508 656387 ret = (int32_t)(Hero.hxofs)*10000;
3509 656387 break;
3510
3511 case LINKHYOFS:
3512 571655 ret = (int32_t)(Hero.hyofs)*10000;
3513 571655 break;
3514
3515 case LINKXOFS:
3516 113145 ret = (int32_t)(Hero.xofs)*10000;
3517 113145 break;
3518
3519 case LINKYOFS:
3520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115547 times.
115547 ret = (int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))*10000;
3521 115547 break;
3522
3523 case HEROSHADOWXOFS:
3524 ret = (int32_t)(Hero.shadowxofs)*10000;
3525 break;
3526
3527 case HEROSHADOWYOFS:
3528 ret = (int32_t)(Hero.shadowyofs)*10000;
3529 break;
3530
3531 case HEROTOTALDYOFFS:
3532 ret = 10000*(((int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))
3533 + ((Hero.switch_hooked && Hero.switchhookstyle == swRISE)
3534 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0));
3535 break;
3536
3537 case LINKZOFS:
3538 ret = (int32_t)(Hero.zofs)*10000;
3539 break;
3540
3541 case LINKHXSZ:
3542 489104 ret = (int32_t)(Hero.hit_width)*10000;
3543 489104 break;
3544
3545 case LINKHYSZ:
3546 489104 ret = (int32_t)(Hero.hit_height)*10000;
3547 489104 break;
3548
3549 case LINKHZSZ:
3550 288295 ret = (int32_t)(Hero.hzsz)*10000;
3551 288295 break;
3552
3553 case LINKTXSZ:
3554 ret = (int32_t)(Hero.txsz)*10000;
3555 break;
3556
3557 case LINKTYSZ:
3558 ret = (int32_t)(Hero.tysz)*10000;
3559 break;
3560
3561 case LINKTILE:
3562 4101 ret = (int32_t)(Hero.tile)*10000;
3563 4101 break;
3564
3565 case LINKFLIP:
3566 ret = (int32_t)(Hero.flip)*10000;
3567 break;
3568
3569 case LINKINVFRAME:
3570 57322 ret = (int32_t)Hero.getHClk()*10000;
3571 57322 break;
3572
3573 case LINKCANFLICKER:
3574 ret= Hero.getCanFlicker()?10000:0;
3575 break;
3576 case LINKHURTSFX:
3577 ret = (int32_t)Hero.getHurtSFX()*10000;
3578 break;
3579
3580 /*
3581 case LINKUSINGITEM:
3582 ret = (int32_t)Hero.getDirectItem()*10000;
3583 break;
3584
3585 case LINKUSINGITEMA:
3586 ret = (int32_t)Hero.getDirectItemA()*10000;
3587 break;
3588
3589 case LINKUSINGITEMB:
3590 ret = (int32_t)Hero.getDirectItemB()*10000;
3591 break;
3592 */
3593
3594 case LINKEATEN:
3595 ret=(int32_t)Hero.getEaten()*10000;
3596 break;
3597 case LINKGRABBED:
3598 ret = Hero.inwallm ? 10000 : 0;
3599 break;
3600 case HEROBUNNY:
3601 ret = Hero.BunnyClock()*10000;
3602 break;
3603 case LINKPUSH:
3604 180367 ret=(int32_t)Hero.getPushing()*10000;
3605 180367 break;
3606 case LINKSTUN:
3607 440770 ret=(int32_t)Hero.StunClock()*10000;
3608 440770 break;
3609 case LINKSCRIPTTILE:
3610 2 ret=script_hero_sprite*10000;
3611 2 break;
3612
3613 case HEROSCRIPTCSET:
3614 ret=script_hero_cset*10000;
3615 break;
3616 case LINKSCRIPFLIP:
3617 ret=script_hero_flip*10000;
3618 break;
3619
3620
3621 case LINKITEMB:
3622 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3623 428588 ret = Bwpn*10000;
3624 428588 break;
3625
3626 case LINKITEMA:
3627 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3628 432590 ret = Awpn *10000;
3629 432590 break;
3630
3631 case LINKITEMX:
3632 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3633 337110 ret = Xwpn *10000;
3634 337110 break;
3635
3636 case LINKITEMY:
3637 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3638 273630 ret = Ywpn *10000;
3639 273630 break;
3640
3641 case LINKTILEMOD:
3642 ret = Hero.getTileModifier() * 10000;
3643 break;
3644
3645 case LINKDIAG:
3646 ret=Hero.getDiagMove()?10000:0;
3647 break;
3648
3649 case LINKBIGHITBOX:
3650 271788 ret=Hero.getBigHitbox()?10000:0;
3651 271788 break;
3652
3653 case LINKCLIMBING:
3654 ret = Hero.getOnSideviewLadder()?10000:0;
3655 break;
3656
3657 case HEROJUMPCOUNT:
3658 ret = Hero.extra_jump_count * 10000;
3659 break;
3660
3661 case HEROPULLDIR:
3662 ret = Hero.pit_pulldir * 10000;
3663 break;
3664
3665 case HEROPULLCLK:
3666 ret = Hero.pit_pullclk * 10000;
3667 break;
3668
3669 case HEROFALLCLK:
3670 832354 ret = Hero.fallclk * 10000;
3671 832354 break;
3672
3673 case HEROFALLCMB:
3674 18 ret = Hero.fallCombo * 10000;
3675 18 break;
3676
3677 case HERODROWNCLK:
3678 ret = Hero.drownclk * 10000;
3679 break;
3680
3681 case HERODROWNCMB:
3682 ret = Hero.drownCombo * 10000;
3683 break;
3684
3685 case HEROFAKEZ:
3686 {
3687
1/2
✓ Branch 0 taken 4357 times.
✗ Branch 1 not taken.
4357 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3688 {
3689 4357 ret = Hero.getFakeZ().getZLong();
3690 4357 }
3691 else ret = int32_t(Hero.getFakeZ()) * 10000;
3692
3693 4357 break;
3694 }
3695
3696 case HEROSHIELDJINX:
3697 ret = Hero.shieldjinxclk * 10000;
3698 break;
3699
3700 case HEROISWARPING:
3701 1012 ret = Hero.is_warping ? 10000L : 0L;
3702 1012 break;
3703
3704 case CLOCKACTIVE:
3705 ret=watch?10000:0;
3706 break;
3707
3708 case CLOCKCLK:
3709 ret=clockclk*10000;
3710 break;
3711
3712 case HERORESPAWNX:
3713 {
3714 ret = Hero.respawn_x.getZLong();
3715 break;
3716 }
3717
3718 case HERORESPAWNY:
3719 {
3720 ret = Hero.respawn_y.getZLong();
3721 break;
3722 }
3723
3724 case HERORESPAWNDMAP:
3725 {
3726 ret = Hero.respawn_dmap * 10000;
3727 break;
3728 }
3729
3730 case HERORESPAWNSCR:
3731 {
3732 ret = Hero.respawn_scr * 10000;
3733 break;
3734 }
3735
3736 case HEROSWITCHTIMER:
3737 {
3738 ret = Hero.switchhookclk * 10000;
3739 break;
3740 }
3741
3742 case HEROSWITCHMAXTIMER:
3743 {
3744 ret = Hero.switchhookmaxtime * 10000;
3745 break;
3746 }
3747
3748 case HEROIMMORTAL:
3749 {
3750 ret = Hero.immortal * 10000;
3751 break;
3752 }
3753
3754 case HEROSTANDING:
3755 {
3756 ret = Hero.isStanding(true) ? 10000 : 0;
3757 break;
3758 }
3759
3760 case HEROCOYOTETIME:
3761 {
3762 ret = Hero.coyotetime*10000;
3763 break;
3764 }
3765
3766 case HEROLIFTEDWPN:
3767 {
3768 ret = Hero.lift_wpn ? Hero.lift_wpn->getUID() : 0;
3769 break;
3770 }
3771 case HEROLIFTTIMER:
3772 {
3773 ret = Hero.liftclk * 10000;
3774 break;
3775 }
3776 case HEROLIFTMAXTIMER:
3777 {
3778 ret = Hero.tliftclk * 10000;
3779 break;
3780 }
3781 case HEROLIFTHEIGHT:
3782 {
3783 ret = Hero.liftheight.getZLong();
3784 break;
3785 }
3786 case HEROHAMMERSTATE:
3787 {
3788 ret = Hero.getHammerState() * 10000;
3789 break;
3790 }
3791 case HEROFLICKERCOLOR:
3792 ret = (int32_t)(Hero.flickercolor) * 10000; break;
3793 case HEROFLASHINGCSET:
3794 136185 ret = (int32_t)(Hero.getFlashingCSet()) * 10000; break;
3795 case HEROFLICKERTRANSP:
3796 ret = (int32_t)(Hero.flickertransp) * 10000; break;
3797
3798 case HEROSLIDING:
3799 ret = Hero.sliding*10000; break;
3800 case HEROICECMB:
3801 ret = Hero.ice_combo*10000; break;
3802 case HEROSCRICECMB:
3803 ret = Hero.script_ice_combo*10000; break;
3804 case HEROICEVX:
3805 ret = Hero.ice_vx.getZLong(); break;
3806 case HEROICEVY:
3807 ret = Hero.ice_vy.getZLong(); break;
3808 case HEROICEENTRYFRAMES:
3809 ret = Hero.ice_entry_count*10000; break;
3810 case HEROICEENTRYMAXFRAMES:
3811 ret = Hero.ice_entry_mcount*10000; break;
3812
3813 ///----------------------------------------------------------------------------------------------------//
3814 //Input States
3815 case INPUTSTART:
3816 92967 ret=control_state[6]?10000:0;
3817 92967 break;
3818
3819 case INPUTMAP:
3820 4123 ret=control_state[9]?10000:0;
3821 4123 break;
3822
3823 case INPUTUP:
3824 4321356 ret=control_state[0]?10000:0;
3825 4321356 break;
3826
3827 case INPUTDOWN:
3828 3824036 ret=control_state[1]?10000:0;
3829 3824036 break;
3830
3831 case INPUTLEFT:
3832 4211785 ret=control_state[2]?10000:0;
3833 4211785 break;
3834
3835 case INPUTRIGHT:
3836 4388042 ret=control_state[3]?10000:0;
3837 4388042 break;
3838
3839 case INPUTA:
3840 6701954 ret=control_state[4]?10000:0;
3841 6701954 break;
3842
3843 case INPUTB:
3844 5699839 ret=control_state[5]?10000:0;
3845 5699839 break;
3846
3847 case INPUTL:
3848 3218568 ret=control_state[7]?10000:0;
3849 3218568 break;
3850
3851 case INPUTR:
3852 3214309 ret=control_state[8]?10000:0;
3853 3214309 break;
3854
3855 case INPUTEX1:
3856 120159 ret=control_state[10]?10000:0;
3857 120159 break;
3858
3859 case INPUTEX2:
3860 120450 ret=control_state[11]?10000:0;
3861 120450 break;
3862
3863 case INPUTEX3:
3864 23391 ret=control_state[12]?10000:0;
3865 23391 break;
3866
3867 case INPUTEX4:
3868 23391 ret=control_state[13]?10000:0;
3869 23391 break;
3870
3871 case INPUTAXISUP:
3872 ret=control_state[14]?10000:0;
3873 break;
3874
3875 case INPUTAXISDOWN:
3876 ret=control_state[15]?10000:0;
3877 break;
3878
3879 case INPUTAXISLEFT:
3880 ret=control_state[16]?10000:0;
3881 break;
3882
3883 case INPUTAXISRIGHT:
3884 ret=control_state[17]?10000:0;
3885 break;
3886
3887 case INPUTMOUSEX:
3888 {
3889 791031 ret=get_mouse_state(0)*10000;
3890 791031 break;
3891 }
3892
3893 case INPUTMOUSEY:
3894 {
3895 791031 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
3896
3/4
✓ Branch 0 taken 24219 times.
✓ Branch 1 taken 766812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 766812 times.
791031 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
3897 791031 ret=((get_mouse_state(1)-tempoffset))*10000;
3898 791031 break;
3899 }
3900
3901 case INPUTMOUSEZ:
3902 ret=(get_mouse_state(2))*10000;
3903 break;
3904
3905 case INPUTMOUSEB:
3906 1073638 ret=(get_mouse_state(3))*10000;
3907 1073638 break;
3908
3909 case INPUTPRESSSTART:
3910 818518 ret=button_press[6]?10000:0;
3911 818518 break;
3912
3913 case INPUTPRESSMAP:
3914 335732 ret=button_press[9]?10000:0;
3915 335732 break;
3916
3917 case INPUTPRESSUP:
3918 1118025 ret=button_press[0]?10000:0;
3919 1118025 break;
3920
3921 case INPUTPRESSDOWN:
3922 1056398 ret=button_press[1]?10000:0;
3923 1056398 break;
3924
3925 case INPUTPRESSLEFT:
3926 963357 ret=button_press[2]?10000:0;
3927 963357 break;
3928
3929 case INPUTPRESSRIGHT:
3930 870340 ret=button_press[3]?10000:0;
3931 870340 break;
3932
3933 case INPUTPRESSA:
3934 2442823 ret=button_press[4]?10000:0;
3935 2442823 break;
3936
3937 case INPUTPRESSB:
3938 1811399 ret=button_press[5]?10000:0;
3939 1811399 break;
3940
3941 case INPUTPRESSL:
3942 2061226 ret=button_press[7]?10000:0;
3943 2061226 break;
3944
3945 case INPUTPRESSR:
3946 1845780 ret=button_press[8]?10000:0;
3947 1845780 break;
3948
3949 case INPUTPRESSEX1:
3950 1237553 ret=button_press[10]?10000:0;
3951 1237553 break;
3952
3953 case INPUTPRESSEX2:
3954 1081361 ret=button_press[11]?10000:0;
3955 1081361 break;
3956
3957 case INPUTPRESSEX3:
3958 558264 ret=button_press[12]?10000:0;
3959 558264 break;
3960
3961 case INPUTPRESSEX4:
3962 669416 ret=button_press[13]?10000:0;
3963 669416 break;
3964
3965 case PRESSAXISUP:
3966 ret=button_press[14]?10000:0;
3967 break;
3968
3969 case PRESSAXISDOWN:
3970 ret=button_press[15]?10000:0;
3971 break;
3972
3973 case PRESSAXISLEFT:
3974 ret=button_press[16]?10000:0;
3975 break;
3976
3977 case PRESSAXISRIGHT:
3978 ret=button_press[17]?10000:0;
3979 break;
3980
3981 case KEYMODIFIERS:
3982 {
3983 ret = (key_shifts*10000);
3984 break;
3985 }
3986
3987 ///----------------------------------------------------------------------------------------------------//
3988 //Itemdata Variables
3989
3990
3991 case IDATAUSEWPN:
3992 if(unsigned(ri->idata) >= MAXITEMS)
3993 {
3994 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3995 ret = -10000;
3996 break;
3997 }
3998 ret=(itemsbuf[ri->idata].weap_data.imitate_weapon)*10000;
3999 break;
4000 case IDATAUSEDEF:
4001 if(unsigned(ri->idata) >= MAXITEMS)
4002 {
4003 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4004 ret = -10000;
4005 break;
4006 }
4007 ret=(itemsbuf[ri->idata].weap_data.default_defense)*10000;
4008 break;
4009 case IDATAWRANGE:
4010 if(unsigned(ri->idata) >= MAXITEMS)
4011 {
4012 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4013 ret = -10000;
4014 break;
4015 }
4016 ret=(itemsbuf[ri->idata].weaprange)*10000;
4017 break;
4018 case IDATAMAGICTIMER:
4019 if(unsigned(ri->idata) >= MAXITEMS)
4020 {
4021 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4022 ret = -10000;
4023 break;
4024 }
4025 ret=(itemsbuf[ri->idata].magiccosttimer[0])*10000;
4026 break;
4027 case IDATAMAGICTIMER2:
4028 if(unsigned(ri->idata) >= MAXITEMS)
4029 {
4030 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4031 ret = -10000;
4032 break;
4033 }
4034 ret=(itemsbuf[ri->idata].magiccosttimer[1])*10000;
4035 break;
4036 // Note: never used?
4037 case IDATAUSEMVT:
4038 {
4039 if(unsigned(ri->idata) >= MAXITEMS)
4040 {
4041 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4042 ret = -10000;
4043 break;
4044 }
4045 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
4046 ret=(itemsbuf[ri->idata].weap_pattern[a])*10000;
4047 }
4048 break;
4049
4050 case IDATADURATION:
4051 if(unsigned(ri->idata) >= MAXITEMS)
4052 {
4053 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4054 ret = -10000;
4055 break;
4056 }
4057 ret=(itemsbuf[ri->idata].weapduration)*10000;
4058 break;
4059
4060 case IDATADUPLICATES:
4061 if(unsigned(ri->idata) >= MAXITEMS)
4062 {
4063 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4064 ret = -10000;
4065 break;
4066 }
4067 ret=(itemsbuf[ri->idata].duplicates)*10000;
4068 break;
4069 case IDATADRAWLAYER:
4070 if(unsigned(ri->idata) >= MAXITEMS)
4071 {
4072 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4073 ret = -10000;
4074 break;
4075 }
4076 ret=(itemsbuf[ri->idata].drawlayer)*10000;
4077 break;
4078 case IDATACOLLECTFLAGS:
4079 if(unsigned(ri->idata) >= MAXITEMS)
4080 {
4081 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4082 ret = 0;
4083 break;
4084 }
4085 ret=(itemsbuf[ri->idata].collectflags)*10000;
4086 break;
4087 case IDATAWEAPONSCRIPT:
4088 if(unsigned(ri->idata) >= MAXITEMS)
4089 {
4090 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4091 ret = -10000;
4092 break;
4093 }
4094 ret=(itemsbuf[ri->idata].weap_data.script)*10000;
4095 break;
4096 case IDATAWEAPHXOFS:
4097 if(unsigned(ri->idata) >= MAXITEMS)
4098 {
4099 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4100 ret = -10000;
4101 break;
4102 }
4103 ret=(itemsbuf[ri->idata].weap_data.hxofs)*10000;
4104 break;
4105 case IDATAWEAPHYOFS:
4106 if(unsigned(ri->idata) >= MAXITEMS)
4107 {
4108 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4109 ret = -10000;
4110 break;
4111 }
4112 ret=(itemsbuf[ri->idata].weap_data.hyofs)*10000;
4113 break;
4114 case IDATAWEAPHXSZ:
4115 if(unsigned(ri->idata) >= MAXITEMS)
4116 {
4117 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4118 ret = -10000;
4119 break;
4120 }
4121 ret=(itemsbuf[ri->idata].weap_data.hxsz)*10000;
4122 break;
4123 case IDATAWEAPHYSZ:
4124 if(unsigned(ri->idata) >= MAXITEMS)
4125 {
4126 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4127 ret = -10000;
4128 break;
4129 }
4130 ret=(itemsbuf[ri->idata].weap_data.hysz)*10000;
4131 break;
4132 case IDATAWEAPHZSZ:
4133 if(unsigned(ri->idata) >= MAXITEMS)
4134 {
4135 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4136 ret = -10000;
4137 break;
4138 }
4139 ret=(itemsbuf[ri->idata].weap_data.hzsz)*10000;
4140 break;
4141 case IDATAWEAPXOFS:
4142 if(unsigned(ri->idata) >= MAXITEMS)
4143 {
4144 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4145 ret = -10000;
4146 break;
4147 }
4148 ret=(itemsbuf[ri->idata].weap_data.xofs)*10000;
4149 break;
4150 case IDATAWEAPYOFS:
4151 if(unsigned(ri->idata) >= MAXITEMS)
4152 {
4153 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4154 ret = -10000;
4155 break;
4156 }
4157 ret=(itemsbuf[ri->idata].weap_data.yofs)*10000;
4158 break;
4159 case IDATAHXOFS:
4160 if(unsigned(ri->idata) >= MAXITEMS)
4161 {
4162 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4163 ret = -10000;
4164 break;
4165 }
4166 ret=(itemsbuf[ri->idata].hxofs)*10000;
4167 break;
4168 case IDATAHYOFS:
4169 if(unsigned(ri->idata) >= MAXITEMS)
4170 {
4171 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4172 ret = -10000;
4173 break;
4174 }
4175 ret=(itemsbuf[ri->idata].hyofs)*10000;
4176 break;
4177 case IDATAHXSZ:
4178 if(unsigned(ri->idata) >= MAXITEMS)
4179 {
4180 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4181 ret = -10000;
4182 break;
4183 }
4184 ret=(itemsbuf[ri->idata].hxsz)*10000;
4185 break;
4186 case IDATAHYSZ:
4187 if(unsigned(ri->idata) >= MAXITEMS)
4188 {
4189 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4190 ret = -10000;
4191 break;
4192 }
4193 ret=(itemsbuf[ri->idata].hysz)*10000;
4194 break;
4195 case IDATAHZSZ:
4196 if(unsigned(ri->idata) >= MAXITEMS)
4197 {
4198 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4199 ret = -10000;
4200 break;
4201 }
4202 ret=(itemsbuf[ri->idata].hzsz)*10000;
4203 break;
4204 case IDATADXOFS:
4205 if(unsigned(ri->idata) >= MAXITEMS)
4206 {
4207 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4208 ret = -10000;
4209 break;
4210 }
4211 ret=(itemsbuf[ri->idata].xofs)*10000;
4212 break;
4213 case IDATADYOFS:
4214 if(unsigned(ri->idata) >= MAXITEMS)
4215 {
4216 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4217 ret = -10000;
4218 break;
4219 }
4220 ret=(itemsbuf[ri->idata].yofs)*10000;
4221 break;
4222 case IDATATILEW:
4223 if(unsigned(ri->idata) >= MAXITEMS)
4224 {
4225 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4226 ret = -10000;
4227 break;
4228 }
4229 ret=(itemsbuf[ri->idata].tilew)*10000;
4230 break;
4231 case IDATATILEH:
4232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ri->idata) >= MAXITEMS)
4233 {
4234 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4235 ret = -10000;
4236 break;
4237 }
4238 53 ret=(itemsbuf[ri->idata].tileh)*10000;
4239 53 break;
4240 case IDATAPICKUP:
4241 if(unsigned(ri->idata) >= MAXITEMS)
4242 {
4243 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4244 ret = -10000;
4245 break;
4246 }
4247 ret=(itemsbuf[ri->idata].pickup)*10000;
4248 break;
4249 case IDATAOVERRIDEFL:
4250 if(unsigned(ri->idata) >= MAXITEMS)
4251 {
4252 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4253 ret = 0;
4254 break;
4255 }
4256 ret=(itemsbuf[ri->idata].overrideFLAGS)*10000;
4257 break;
4258
4259 case IDATATILEWWEAP:
4260 if(unsigned(ri->idata) >= MAXITEMS)
4261 {
4262 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4263 ret = -10000;
4264 break;
4265 }
4266 ret=(itemsbuf[ri->idata].weap_data.tilew)*10000;
4267 break;
4268 case IDATATILEHWEAP:
4269 if(unsigned(ri->idata) >= MAXITEMS)
4270 {
4271 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4272 ret = -10000;
4273 break;
4274 }
4275 ret=(itemsbuf[ri->idata].weap_data.tileh)*10000;
4276 break;
4277 case IDATAOVERRIDEFLWEAP:
4278 if(unsigned(ri->idata) >= MAXITEMS)
4279 {
4280 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4281 ret = 0;
4282 break;
4283 }
4284 ret=(itemsbuf[ri->idata].weap_data.override_flags)*10000;
4285 break;
4286
4287 case IDATAFAMILY:
4288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5960535 times.
5960535 if(unsigned(ri->idata) >= MAXITEMS)
4289 {
4290 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4291 ret = -10000;
4292 break;
4293 }
4294 5960535 ret=(itemsbuf[ri->idata].family)*10000;
4295 5960535 break;
4296
4297 case IDATALEVEL:
4298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16858 times.
16858 if(unsigned(ri->idata) >= MAXITEMS)
4299 {
4300 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4301 ret = -10000;
4302 break;
4303 }
4304 16858 ret=(itemsbuf[ri->idata].fam_type)*10000;
4305 16858 break;
4306
4307 case IDATAKEEP:
4308 3 ret = item_flag(item_gamedata);
4309 3 break;
4310
4311 case IDATAAMOUNT:
4312 {
4313 if(unsigned(ri->idata) >= MAXITEMS)
4314 {
4315 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4316 ret = -10000;
4317 break;
4318 }
4319 int32_t v = itemsbuf[ri->idata].amount;
4320 ret = ((v&0x4000)?-1:1)*(v & 0x3FFF)*10000;
4321 break;
4322 }
4323 case IDATAGRADUAL:
4324 {
4325 if(unsigned(ri->idata) >= MAXITEMS)
4326 {
4327 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4328 ret = -10000;
4329 break;
4330 }
4331 ret = (itemsbuf[ri->idata].amount&0x8000) ? 10000 : 0;
4332 break;
4333 }
4334 case IDATACONSTSCRIPT:
4335 ret = item_flag(item_passive_script);
4336 break;
4337 case IDATASSWIMDISABLED:
4338 ret = item_flag(item_sideswim_disabled);
4339 break;
4340 case IDATABUNNYABLE:
4341 ret = item_flag(item_bunny_enabled);
4342 break;
4343 case IDATAJINXIMMUNE:
4344 ret = item_flag(item_jinx_immune);
4345 break;
4346 case IDATAJINXSWAP:
4347 ret = item_flag(item_flip_jinx);
4348 break;
4349 case IDATAUSEBURNSPR:
4350 if(unsigned(ri->idata) >= MAXITEMS)
4351 {
4352 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4353 ret = 0;
4354 }
4355 else ret = (itemsbuf[ri->idata].weap_data.wflags & WFLAG_UPDATE_IGNITE_SPRITE) ? 10000 : 0;
4356 break;
4357
4358 case IDATASETMAX:
4359 if(unsigned(ri->idata) >= MAXITEMS)
4360 {
4361 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4362 ret = -10000;
4363 break;
4364 }
4365 ret=(itemsbuf[ri->idata].setmax)*10000;
4366 break;
4367
4368 case IDATAMAX:
4369 if(unsigned(ri->idata) >= MAXITEMS)
4370 {
4371 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4372 ret = -10000;
4373 break;
4374 }
4375 ret=(itemsbuf[ri->idata].max)*10000;
4376 break;
4377
4378 case IDATACOUNTER:
4379 if(unsigned(ri->idata) >= MAXITEMS)
4380 {
4381 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4382 ret = -10000;
4383 break;
4384 }
4385 ret=(itemsbuf[ri->idata].count)*10000;
4386 break;
4387
4388 case IDATAPSOUND:
4389 if(unsigned(ri->idata) >= MAXITEMS)
4390 {
4391 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4392 ret = -10000;
4393 break;
4394 }
4395 ret=(itemsbuf[ri->idata].playsound)*10000;
4396 break;
4397 case IDATAUSESOUND:
4398 if(unsigned(ri->idata) >= MAXITEMS)
4399 {
4400 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4401 ret = -10000;
4402 break;
4403 }
4404 ret=(itemsbuf[ri->idata].usesound)*10000;
4405 break;
4406
4407 case IDATAUSESOUND2:
4408 if(unsigned(ri->idata) >= MAXITEMS)
4409 {
4410 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4411 ret = -10000;
4412 break;
4413 }
4414 ret=(itemsbuf[ri->idata].usesound2)*10000;
4415 break;
4416
4417 case IDATAPOWER:
4418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1994 times.
1994 if(unsigned(ri->idata) >= MAXITEMS)
4419 {
4420 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4421 ret = -10000;
4422 break;
4423 }
4424 1994 ret=(itemsbuf[ri->idata].power)*10000;
4425 1994 break;
4426
4427 //Get the ID of an item.
4428 case IDATAID:
4429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1914 times.
1914 if(unsigned(ri->idata) >= MAXITEMS)
4430 {
4431 //Don't error here //scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4432 ret = -10000;
4433 break;
4434 }
4435 1914 ret=ri->idata*10000;
4436 1914 break;
4437
4438 //Get the script assigned to an item (active)
4439 case IDATASCRIPT:
4440 if(unsigned(ri->idata) >= MAXITEMS)
4441 {
4442 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4443 ret = -10000;
4444 break;
4445 }
4446 ret=(itemsbuf[ri->idata].script)*10000;
4447 break;
4448 case IDATASPRSCRIPT:
4449 if(unsigned(ri->idata) >= MAXITEMS)
4450 {
4451 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4452 ret = -10000;
4453 break;
4454 }
4455 ret=(itemsbuf[ri->idata].sprite_script)*10000;
4456 break;
4457 //Hero TIle modifier
4458 case IDATALTM:
4459 if(unsigned(ri->idata) >= MAXITEMS)
4460 {
4461 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4462 ret = 0;
4463 break;
4464 }
4465 ret=(itemsbuf[ri->idata].ltm)*10000;
4466 break;
4467 //Pickup script
4468 case IDATAPSCRIPT:
4469 if(unsigned(ri->idata) >= MAXITEMS)
4470 {
4471 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4472 ret = -10000;
4473 break;
4474 }
4475 ret=(itemsbuf[ri->idata].collect_script)*10000;
4476 break;
4477 //Pickup string
4478 case IDATAPSTRING:
4479 if(unsigned(ri->idata) >= MAXITEMS)
4480 {
4481 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4482 ret = -10000;
4483 break;
4484 }
4485 ret=(itemsbuf[ri->idata].pstring)*10000;
4486 break;
4487 case IDATAPFLAGS:
4488 if(unsigned(ri->idata) >= MAXITEMS)
4489 {
4490 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4491 ret = 0;
4492 break;
4493 }
4494 ret = (itemsbuf[ri->idata].pickup_string_flags)*10000;
4495 break;
4496 case IDATAPICKUPLITEMS:
4497 if(unsigned(ri->idata) >= MAXITEMS)
4498 {
4499 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4500 ret = 0;
4501 break;
4502 }
4503 ret = (itemsbuf[ri->idata].pickup_litems)*10000;
4504 break;
4505 case IDATAPICKUPLITEMLEVEL:
4506 if(unsigned(ri->idata) >= MAXITEMS)
4507 {
4508 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4509 ret = 0;
4510 break;
4511 }
4512 ret = (itemsbuf[ri->idata].pickup_litem_level)*10000;
4513 break;
4514 //Magic cost
4515 case IDATAMAGCOST:
4516 if(unsigned(ri->idata) >= MAXITEMS)
4517 {
4518 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4519 ret = -10000;
4520 break;
4521 }
4522 ret=(itemsbuf[ri->idata].cost_amount[0])*10000;
4523 break;
4524 case IDATACOST2:
4525 if(unsigned(ri->idata) >= MAXITEMS)
4526 {
4527 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4528 ret = -10000;
4529 break;
4530 }
4531 ret=(itemsbuf[ri->idata].cost_amount[1])*10000;
4532 break;
4533 //cost counter ref
4534 case IDATACOSTCOUNTER:
4535 if(unsigned(ri->idata) >= MAXITEMS)
4536 {
4537 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4538 ret = -10000;
4539 break;
4540 }
4541 ret=(itemsbuf[ri->idata].cost_counter[0])*10000;
4542 break;
4543 case IDATACOSTCOUNTER2:
4544 if(unsigned(ri->idata) >= MAXITEMS)
4545 {
4546 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4547 ret = -10000;
4548 break;
4549 }
4550 ret=(itemsbuf[ri->idata].cost_counter[1])*10000;
4551 break;
4552 //Min Hearts to Pick Up
4553 case IDATAMINHEARTS:
4554 if(unsigned(ri->idata) >= MAXITEMS)
4555 {
4556 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4557 ret = -10000;
4558 break;
4559 }
4560 ret=(itemsbuf[ri->idata].pickup_hearts)*10000;
4561 break;
4562 //Tile used by the item
4563 case IDATATILE:
4564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55670 times.
55670 if(unsigned(ri->idata) >= MAXITEMS)
4565 {
4566 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4567 ret = -10000;
4568 break;
4569 }
4570 55670 ret=(itemsbuf[ri->idata].tile)*10000;
4571 55670 break;
4572 //itemdata->Flash
4573 case IDATAMISC:
4574 if(unsigned(ri->idata) >= MAXITEMS)
4575 {
4576 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4577 ret = -10000;
4578 break;
4579 }
4580 ret=(itemsbuf[ri->idata].misc_flags)*10000;
4581 break;
4582 //->CSet
4583 case IDATACSET:
4584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55645 times.
55645 if(unsigned(ri->idata) >= MAXITEMS)
4585 {
4586 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4587 ret = -10000;
4588 break;
4589 }
4590
4591 55645 ret = (itemsbuf[ri->idata].csets&15)*10000;
4592
4593 // If we find quests that broke, use this code.
4594 // if (QHeader.compareVer(2, 55, 9) >= 0)
4595 // ret = (itemsbuf[ri->idata].csets&15)*10000;
4596 // else
4597 // ret = itemsbuf[ri->idata].csets*10000;
4598 55645 break;
4599 case IDATAFLASHCSET:
4600 if(unsigned(ri->idata) >= MAXITEMS)
4601 {
4602 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4603 ret = -10000;
4604 break;
4605 }
4606 ret=(itemsbuf[ri->idata].csets>>4)*10000;
4607 break;
4608 //->A.Frames
4609 case IDATAFRAMES:
4610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63041 times.
63041 if(unsigned(ri->idata) >= MAXITEMS)
4611 {
4612 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4613 ret = -10000;
4614 break;
4615 }
4616 63041 ret=(itemsbuf[ri->idata].frames)*10000;
4617 63041 break;
4618 /*
4619 case IDATAFRAME:
4620 ret=(itemsbuf[ri->idata].frame)*10000;
4621 break;
4622 */
4623 //->A.Speed
4624 case IDATAASPEED:
4625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 142873 times.
142873 if(unsigned(ri->idata) >= MAXITEMS)
4626 {
4627 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4628 ret = -10000;
4629 break;
4630 }
4631 142873 ret=(itemsbuf[ri->idata].speed)*10000;
4632 142873 break;
4633 //->Delay
4634 case IDATADELAY:
4635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74538 times.
74538 if(unsigned(ri->idata) >= MAXITEMS)
4636 {
4637 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4638 ret = -10000;
4639 break;
4640 }
4641 74538 ret=(itemsbuf[ri->idata].delay)*10000;
4642 74538 break;
4643 // teo of this item upgrades
4644 case IDATACOMBINE:
4645 ret = item_flag(item_combine);
4646 break;
4647 //Use item, and get the lower level one
4648 case IDATADOWNGRADE:
4649 ret = item_flag(item_downgrade);
4650 break;
4651 //Only validate the cost, don't charge it
4652 case IDATAVALIDATE:
4653 ret = item_flag(item_validate_only);
4654 break;
4655 case IDATAVALIDATE2:
4656 ret = item_flag(item_validate_only_2);
4657 break;
4658 //->Keep Old
4659 case IDATAKEEPOLD:
4660 ret = item_flag(item_keep_old);
4661 break;
4662 //Use rupees instead of magic
4663 case IDATARUPEECOST:
4664 ret = item_flag(item_rupee_magic);
4665 break;
4666 //Can be eaten
4667 case IDATAEDIBLE:
4668 ret = item_flag(item_edible);
4669 break;
4670 //currently unused
4671 case IDATAFLAGUNUSED:
4672 ret = item_flag(item_unused);
4673 break;
4674 //Gain lower level items when collected
4675 case IDATAGAINLOWER:
4676 ret = item_flag(item_gain_old);
4677 break;
4678
4679 ///----------------------------------------------------------------------------------------------------//
4680 //LWeapon Variables
4681 case LWPNSPECIAL:
4682 if(0!=(s=checkLWpn(ri->lwpn)))
4683 ret=((int32_t)((weapon*)(s))->specialinfo)*10000;
4684
4685
4686 break;
4687
4688 case LWPNSCALE:
4689 if ( get_qr(qr_OLDSPRITEDRAWS) )
4690 {
4691 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
4692 ret = -1; break;
4693 }
4694 if(0!=(s=checkLWpn(ri->lwpn)))
4695 ret=((int32_t)((weapon*)(s))->scale)*100.0;
4696
4697 break;
4698
4699 case LWPNX:
4700
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 939265 times.
954757 if(0!=(s=checkLWpn(ri->lwpn)))
4701 {
4702
2/2
✓ Branch 0 taken 350528 times.
✓ Branch 1 taken 588737 times.
939265 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4703 {
4704 350528 ret=(((weapon*)(s))->x).getZLong();
4705 350528 }
4706 else
4707 588737 ret=((int32_t)((weapon*)(s))->x)*10000;
4708 939265 }
4709
4710 954757 break;
4711
4712 case SPRITEMAXLWPN:
4713 {
4714 //No bounds check, as this is a universal function and works from NULL pointers!
4715 ret = Lwpns.getMax() * 10000;
4716 break;
4717 }
4718
4719 case LWPNY:
4720
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 934658 times.
950150 if(0!=(s=checkLWpn(ri->lwpn)))
4721 {
4722
2/2
✓ Branch 0 taken 350395 times.
✓ Branch 1 taken 584263 times.
934658 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4723 {
4724 350395 ret=(((weapon*)(s))->y).getZLong();
4725 350395 }
4726 else
4727 584263 ret=((int32_t)((weapon*)(s))->y)*10000;
4728 934658 }
4729 950150 break;
4730
4731 case LWPNZ:
4732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109736 times.
109736 if(0!=(s=checkLWpn(ri->lwpn)))
4733 {
4734
2/2
✓ Branch 0 taken 53984 times.
✓ Branch 1 taken 55752 times.
109736 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4735 {
4736 53984 ret=(((weapon*)(s))->z).getZLong();
4737 53984 }
4738 else
4739 55752 ret=((int32_t)((weapon*)(s))->z)*10000;
4740 109736 }
4741
4742 109736 break;
4743
4744 case LWPNJUMP:
4745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4746 {
4747 6 ret = ((weapon*)(s))->fall.getZLong() / -100;
4748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4749 6 }
4750
4751 6 break;
4752
4753 case LWPNFAKEJUMP:
4754 if(0!=(s=checkLWpn(ri->lwpn)))
4755 {
4756 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
4757 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4758 }
4759
4760 break;
4761
4762 case LWPNDIR:
4763
1/2
✓ Branch 0 taken 80933 times.
✗ Branch 1 not taken.
80933 if(0!=(s=checkLWpn(ri->lwpn)))
4764 80933 ret=((weapon*)(s))->dir*10000;
4765
4766 80933 break;
4767
4768 case LWPNGRAVITY:
4769 if(0!=(s=checkLWpn(ri->lwpn)))
4770 ret= (((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0;
4771
4772 break;
4773
4774 case LWPNSTEP:
4775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5388 times.
5388 if(0!=(s=checkLWpn(ri->lwpn)))
4776 {
4777
3/4
✓ Branch 0 taken 1140 times.
✓ Branch 1 taken 4248 times.
✓ Branch 2 taken 1140 times.
✗ Branch 3 not taken.
5388 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
4778 {
4779 5388 ret=((weapon*)s)->step.getZLong() * 100;
4780 5388 }
4781 //old, buggy code replication, round two: Go! -Z
4782 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
4783
4784 //else
4785 //{
4786 //old, buggy code replication, round THREE: Go! -Z
4787 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
4788 // ret = (int32_t)tmp;
4789 //}
4790
4791 //old, buggy code replication, round FOUR: Go! -Z
4792 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
4793 5388 }
4794 5388 break;
4795
4796 case LWPNANGLE:
4797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
416 if(0!=(s=checkLWpn(ri->lwpn)))
4798 416 ret=(int32_t)(((weapon*)(s))->angle*10000);
4799
4800 416 break;
4801
4802 case LWPNDEGANGLE:
4803 if(0!=(s=checkLWpn(ri->lwpn)))
4804 {
4805 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
4806 }
4807
4808 break;
4809
4810 case LWPNVX:
4811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if(0!=(s=checkLWpn(ri->lwpn)))
4812 {
4813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if (((weapon*)(s))->angular)
4814 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4815 else
4816 {
4817
4/7
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 122 times.
✓ Branch 6 taken 124 times.
246 switch(NORMAL_DIR(((weapon*)(s))->dir))
4818 {
4819 case l_up:
4820 case l_down:
4821 case left:
4822 ret = int32_t(-10000.0*((weapon*)s)->step);
4823 break;
4824
4825 case r_down:
4826 case r_up:
4827 case right:
4828 122 ret = int32_t(10000.0*((weapon*)s)->step);
4829 122 break;
4830
4831 default:
4832 124 ret = 0;
4833 124 break;
4834 }
4835 }
4836 246 }
4837
4838 246 break;
4839
4840 case LWPNVY:
4841 if(0!=(s=checkLWpn(ri->lwpn)))
4842 {
4843 if (((weapon*)(s))->angular)
4844 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4845 else
4846 {
4847 switch(NORMAL_DIR(((weapon*)(s))->dir))
4848 {
4849 case l_up:
4850 case r_up:
4851 case up:
4852 ret = int32_t(-10000.0*((weapon*)s)->step);
4853 break;
4854 case l_down:
4855 case r_down:
4856 case down:
4857 ret = int32_t(10000.0*((weapon*)s)->step);
4858 break;
4859
4860 default:
4861 ret = 0;
4862 break;
4863 }
4864 }
4865 }
4866
4867 break;
4868
4869 case LWPNANGULAR:
4870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4871 6 ret=((weapon*)(s))->angular*10000;
4872
4873 6 break;
4874
4875 case LWPNAUTOROTATE:
4876 if(0!=(s=checkLWpn(ri->lwpn)))
4877 ret=((weapon*)(s))->autorotate*10000;
4878
4879 break;
4880
4881 case LWPNBEHIND:
4882 if(0!=(s=checkLWpn(ri->lwpn)))
4883 ret=((weapon*)(s))->behind*10000;
4884
4885 break;
4886
4887 case LWPNDRAWTYPE:
4888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4889 6 ret=((weapon*)(s))->drawstyle*10000;
4890
4891 6 break;
4892
4893 case LWPNPOWER:
4894
2/2
✓ Branch 0 taken 103895 times.
✓ Branch 1 taken 1 times.
103896 if(0!=(s=checkLWpn(ri->lwpn)))
4895 103895 ret=((weapon*)(s))->power*10000;
4896
4897 103896 break;
4898 /*
4899 case LWPNRANGE:
4900 if(0!=(s=checkLWpn(ri->lwpn)))
4901 ret=((weapon*)(s))->scriptrange*10000;
4902
4903 break;
4904 */
4905 case LWPNDEAD:
4906
1/2
✓ Branch 0 taken 7611 times.
✗ Branch 1 not taken.
7611 if(0!=(s=checkLWpn(ri->lwpn)))
4907 7611 ret=((weapon*)(s))->dead*10000;
4908
4909 7611 break;
4910
4911 case LWPNID:
4912
2/2
✓ Branch 0 taken 16620 times.
✓ Branch 1 taken 4092488 times.
4109108 if(0!=(s=checkLWpn(ri->lwpn)))
4913 4092488 ret=((weapon*)(s))->id*10000;
4914
4915 4109108 break;
4916
4917 case LWPNTILE:
4918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53697 times.
53697 if(0!=(s=checkLWpn(ri->lwpn)))
4919 53697 ret=((weapon*)(s))->tile*10000;
4920
4921 53697 break;
4922
4923 case LWPNSCRIPTTILE:
4924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if(0!=(s=checkLWpn(ri->lwpn)))
4925 586 ret=((weapon*)(s))->scripttile*10000;
4926
4927 586 break;
4928
4929 case LWPNSCRIPTFLIP:
4930 if(0!=(s=checkLWpn(ri->lwpn)))
4931 ret=((weapon*)(s))->scriptflip*10000;
4932
4933 break;
4934
4935 case LWPNCSET:
4936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53381 times.
53381 if(0!=(s=checkLWpn(ri->lwpn)))
4937 53381 ret=((weapon*)(s))->cs*10000;
4938
4939 53381 break;
4940
4941 case LWPNFLASHCSET:
4942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 220 times.
220 if(0!=(s=checkLWpn(ri->lwpn)))
4943 220 ret=(((weapon*)(s))->o_cset>>4)*10000;
4944
4945 220 break;
4946
4947 case LWPNFRAMES:
4948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
4949 4362 ret=((weapon*)(s))->frames*10000;
4950
4951 4362 break;
4952
4953 case LWPNFRAME:
4954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4955 6 ret=((weapon*)(s))->aframe*10000;
4956
4957 6 break;
4958
4959 case LWPNASPEED:
4960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
4961 4362 ret=((weapon*)(s))->o_speed*10000;
4962
4963 4362 break;
4964
4965 case LWPNFLASH:
4966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4967 6 ret=((weapon*)(s))->flash*10000;
4968
4969 6 break;
4970
4971 case LWPNFLIP:
4972 if(0!=(s=checkLWpn(ri->lwpn)))
4973 ret=((weapon*)(s))->flip*10000;
4974
4975 break;
4976
4977 case LWPNCOUNT:
4978 1950927 ret=Lwpns.Count()*10000;
4979 1950927 break;
4980
4981 case LWPNEXTEND:
4982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4983 6 ret=((weapon*)(s))->extend*10000;
4984
4985 6 break;
4986
4987 case LWPNOTILE:
4988
1/2
✓ Branch 0 taken 835937 times.
✗ Branch 1 not taken.
835937 if(0!=(s=checkLWpn(ri->lwpn)))
4989 835937 ret=((weapon*)(s))->o_tile*10000;
4990
4991 835937 break;
4992
4993 case LWPNOCSET:
4994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23909 times.
23909 if(0!=(s=checkLWpn(ri->lwpn)))
4995 23909 ret=(((weapon*)(s))->o_cset&15)*10000;
4996
4997 23909 break;
4998
4999 case LWPNHXOFS:
5000
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 284226 times.
299718 if(0!=(s=checkLWpn(ri->lwpn)))
5001 284226 ret=(((weapon*)(s))->hxofs)*10000;
5002
5003 299718 break;
5004
5005 case LWPNHYOFS:
5006
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 281478 times.
296970 if(0!=(s=checkLWpn(ri->lwpn)))
5007 281478 ret=(((weapon*)(s))->hyofs)*10000;
5008
5009 296970 break;
5010
5011 case LWPNXOFS:
5012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10231 times.
10231 if(0!=(s=checkLWpn(ri->lwpn)))
5013 10231 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
5014
5015 10231 break;
5016
5017 case LWPNYOFS:
5018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 if(0!=(s=checkLWpn(ri->lwpn)))
5019
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5020
5021 11477 break;
5022
5023 case LWPNSHADOWXOFS:
5024 if(0!=(s=checkLWpn(ri->lwpn)))
5025 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5026
5027 break;
5028
5029 case LWPNSHADOWYOFS:
5030 if(0!=(s=checkLWpn(ri->lwpn)))
5031 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5032
5033 break;
5034
5035 case LWPNTOTALDYOFFS:
5036 if(0!=(s=checkLWpn(ri->lwpn)))
5037 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5038 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5039 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0)) * 10000;
5040 break;
5041
5042 case LWPNZOFS:
5043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5044 6 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5045
5046 6 break;
5047
5048 case LWPNHXSZ:
5049
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 267550 times.
283042 if(0!=(s=checkLWpn(ri->lwpn)))
5050 267550 ret=(((weapon*)(s))->hit_width)*10000;
5051
5052 283042 break;
5053
5054 case LWPNHYSZ:
5055
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 269504 times.
284996 if(0!=(s=checkLWpn(ri->lwpn)))
5056 269504 ret=(((weapon*)(s))->hit_height)*10000;
5057
5058 284996 break;
5059
5060 case LWPNHZSZ:
5061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36540 times.
36540 if(0!=(s=checkLWpn(ri->lwpn)))
5062 36540 ret=(((weapon*)(s))->hzsz)*10000;
5063
5064 36540 break;
5065
5066 case LWPNTXSZ:
5067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5068 32019 ret=(((weapon*)(s))->txsz)*10000;
5069
5070 32019 break;
5071
5072 case LWPNTYSZ:
5073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5074 32019 ret=(((weapon*)(s))->tysz)*10000;
5075
5076 32019 break;
5077
5078 case LWPNCOLLDET:
5079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5455 times.
5455 if(0!=(s=checkLWpn(ri->lwpn)))
5080 5455 ret=(((weapon*)(s))->scriptcoldet)*10000;
5081
5082 5455 break;
5083
5084 case LWPNENGINEANIMATE:
5085 if(0!=(s=checkLWpn(ri->lwpn)))
5086 ret=(((weapon*)(s))->do_animation)*10000;
5087
5088 break;
5089
5090 case LWPNPARENT:
5091 if(0!=(s=checkLWpn(ri->lwpn)))
5092 ret=(((weapon*)(s))->parentitem)*10000;
5093
5094 break;
5095
5096 case LWPNLEVEL:
5097 if(0!=(s=checkLWpn(ri->lwpn)))
5098 ret=(((weapon*)(s))->type)*10000;
5099
5100 break;
5101
5102 case LWPNSCRIPT:
5103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(0!=(s=checkLWpn(ri->lwpn)))
5104 3 ret=(((weapon*)(s))->script)*10000;
5105
5106 3 break;
5107
5108 case LWPNUSEWEAPON:
5109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60075 times.
60075 if(0!=(s=checkLWpn(ri->lwpn)))
5110 60075 ret=(((weapon*)(s))->useweapon)*10000;
5111
5112 60075 break;
5113
5114 case LWPNUSEDEFENCE:
5115 if(0!=(s=checkLWpn(ri->lwpn)))
5116 ret=(((weapon*)(s))->usedefense)*10000;
5117
5118 break;
5119
5120 case LWEAPONSCRIPTUID:
5121 if(0!=(s=checkLWpn(ri->lwpn)))
5122 ret=(((weapon*)(s))->getUID());
5123
5124 break;
5125
5126 case LWPNROTATION:
5127 if ( get_qr(qr_OLDSPRITEDRAWS) )
5128 {
5129 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5130 ret = -1; break;
5131 }
5132 if(0!=(s=checkLWpn(ri->lwpn)))
5133 ret=((weapon*)(s))->rotation*10000;
5134
5135 break;
5136
5137 case LWPNFALLCLK:
5138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1552 times.
1552 if(0!=(s=checkLWpn(ri->lwpn)))
5139 {
5140 1552 ret = ((weapon*)(s))->fallclk * 10000;
5141 1552 }
5142 1552 break;
5143
5144 case LWPNFALLCMB:
5145 if(0!=(s=checkLWpn(ri->lwpn)))
5146 {
5147 ret = ((weapon*)(s))->fallCombo * 10000;
5148 }
5149 break;
5150
5151 case LWPNDROWNCLK:
5152 if(0!=(s=checkLWpn(ri->lwpn)))
5153 {
5154 ret = ((weapon*)(s))->drownclk * 10000;
5155 }
5156 break;
5157
5158 case LWPNDROWNCMB:
5159 if(0!=(s=checkLWpn(ri->lwpn)))
5160 {
5161 ret = ((weapon*)(s))->drownCombo * 10000;
5162 }
5163 break;
5164
5165 case LWPNFAKEZ:
5166 if(0!=(s=checkLWpn(ri->lwpn)))
5167 {
5168 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5169 {
5170 ret=(((weapon*)(s))->fakez).getZLong();
5171 }
5172 else
5173 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5174 }
5175 break;
5176
5177 case LWPNGLOWRAD:
5178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48553 times.
48553 if(0!=(s=checkLWpn(ri->lwpn)))
5179 {
5180 48553 ret = ((weapon*)(s))->glowRad * 10000;
5181 48553 }
5182 48553 break;
5183
5184 case LWPNGLOWSHP:
5185 if(0!=(s=checkLWpn(ri->lwpn)))
5186 {
5187 ret = ((weapon*)(s))->glowShape * 10000;
5188 }
5189 break;
5190
5191 case LWPNUNBL:
5192 if(0!=(s=checkLWpn(ri->lwpn)))
5193 {
5194 ret = ((weapon*)(s))->unblockable * 10000;
5195 }
5196 break;
5197
5198 case LWPNSHADOWSPR:
5199 if(0!=(s=checkLWpn(ri->lwpn)))
5200 {
5201 ret = ((weapon*)(s))->spr_shadow * 10000;
5202 }
5203 break;
5204 case LWSWHOOKED:
5205 if(0!=(s=checkLWpn(ri->lwpn)))
5206 {
5207 ret = s->switch_hooked ? 10000 : 0;
5208 }
5209 break;
5210 case LWPNTIMEOUT:
5211 if(0!=(s=checkLWpn(ri->lwpn)))
5212 {
5213 ret = ((weapon*)(s))->weap_timeout * 10000;
5214 }
5215 break;
5216 case LWPNDEATHITEM:
5217 if(0!=(s=checkLWpn(ri->lwpn)))
5218 {
5219 ret = ((weapon*)(s))->death_spawnitem * 10000;
5220 }
5221 break;
5222 case LWPNDEATHDROPSET:
5223 if(0!=(s=checkLWpn(ri->lwpn)))
5224 {
5225 ret = ((weapon*)(s))->death_spawndropset * 10000;
5226 }
5227 break;
5228 case LWPNDEATHIPICKUP:
5229 if(0!=(s=checkLWpn(ri->lwpn)))
5230 {
5231 ret = ((weapon*)(s))->death_item_pflags * 10000;
5232 }
5233 break;
5234 case LWPNDEATHSPRITE:
5235 if(0!=(s=checkLWpn(ri->lwpn)))
5236 {
5237 ret = ((weapon*)(s))->death_sprite * 10000;
5238 }
5239 break;
5240 case LWPNDEATHSFX:
5241 if(0!=(s=checkLWpn(ri->lwpn)))
5242 {
5243 ret = ((weapon*)(s))->death_sfx * 10000;
5244 }
5245 break;
5246 case LWPNLIFTLEVEL:
5247 if(0!=(s=checkLWpn(ri->lwpn)))
5248 {
5249 ret = ((weapon*)(s))->lift_level * 10000;
5250 }
5251 break;
5252 case LWPNLIFTTIME:
5253 if(0!=(s=checkLWpn(ri->lwpn)))
5254 {
5255 ret = ((weapon*)(s))->lift_time * 10000;
5256 }
5257 break;
5258 case LWPNLIFTHEIGHT:
5259 if(0!=(s=checkLWpn(ri->lwpn)))
5260 {
5261 ret = ((weapon*)(s))->lift_height.getZLong();
5262 }
5263 break;
5264
5265 ///----------------------------------------------------------------------------------------------------//
5266 //EWeapon Variables
5267 case EWPNSCALE:
5268 if ( get_qr(qr_OLDSPRITEDRAWS) )
5269 {
5270 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5271 ret = -1; break;
5272 }
5273 if(0!=(s=checkEWpn(ri->ewpn)))
5274 ret=((int32_t)((weapon*)(s))->scale)*100.0;
5275
5276 break;
5277
5278 case EWPNX:
5279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354386 times.
4354386 if(0!=(s=checkEWpn(ri->ewpn)))
5280 {
5281
2/2
✓ Branch 0 taken 219258 times.
✓ Branch 1 taken 4135128 times.
4354386 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5282 {
5283 219258 ret=(((weapon*)(s))->x).getZLong();
5284 219258 }
5285 else
5286 4135128 ret=((int32_t)((weapon*)(s))->x)*10000;
5287 4354386 }
5288 4354386 break;
5289
5290 case SPRITEMAXEWPN:
5291 {
5292 //No bounds check, as this is a universal function and works from NULL pointers!
5293 ret = Ewpns.getMax() * 10000;
5294 break;
5295 }
5296
5297 case EWPNY:
5298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354484 times.
4354484 if(0!=(s=checkEWpn(ri->ewpn)))
5299 {
5300
2/2
✓ Branch 0 taken 219111 times.
✓ Branch 1 taken 4135373 times.
4354484 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5301 {
5302 219111 ret=(((weapon*)(s))->y).getZLong();
5303 219111 }
5304 else
5305 4135373 ret=((int32_t)((weapon*)(s))->y)*10000;
5306 4354484 }
5307 4354484 break;
5308
5309 case EWPNZ:
5310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552907 times.
552907 if(0!=(s=checkEWpn(ri->ewpn)))
5311 {
5312
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 551475 times.
552907 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5313 {
5314 1432 ret=(((weapon*)(s))->z).getZLong();
5315 1432 }
5316 else
5317 551475 ret=((int32_t)((weapon*)(s))->z)*10000;
5318 552907 }
5319 552907 break;
5320
5321 case EWPNJUMP:
5322 if(0!=(s=checkEWpn(ri->ewpn)))
5323 {
5324 ret = ((weapon*)(s))->fall.getZLong() / -100;
5325 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5326 }
5327
5328 break;
5329
5330 case EWPNFAKEJUMP:
5331 if(0!=(s=checkEWpn(ri->ewpn)))
5332 {
5333 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
5334 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5335 }
5336
5337 break;
5338
5339 case EWPNDIR:
5340
1/2
✓ Branch 0 taken 61563 times.
✗ Branch 1 not taken.
61563 if(0!=(s=checkEWpn(ri->ewpn)))
5341 61563 ret=((weapon*)(s))->dir*10000;
5342
5343 61563 break;
5344
5345 case EWPNLEVEL:
5346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2845 times.
2845 if(0!=(s=checkEWpn(ri->ewpn)))
5347 2845 ret=((weapon*)(s))->type*10000;
5348
5349 2845 break;
5350
5351 case EWPNGRAVITY:
5352 if(0!=(s=checkEWpn(ri->ewpn)))
5353 ret=((((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0);
5354
5355 break;
5356
5357 case EWPNSTEP:
5358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 610345 times.
610345 if(0!=(s=checkEWpn(ri->ewpn)))
5359 {
5360
3/4
✓ Branch 0 taken 610183 times.
✓ Branch 1 taken 162 times.
✓ Branch 2 taken 610183 times.
✗ Branch 3 not taken.
610345 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
5361 {
5362 610345 ret=((weapon*)s)->step.getZLong() * 100;
5363 610345 }
5364 //old, buggy code replication, round two: Go! -Z
5365 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
5366 //old, buggy code replication, round FOUR: Go! -Z
5367 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
5368 610345 }
5369 //else
5370 //{
5371 //old, buggy code replication, round THREE: Go! -Z
5372 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
5373 // ret = int32_t(tmp);
5374 //}
5375 610345 break;
5376
5377 case EWPNANGLE:
5378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 718383 times.
718383 if(0!=(s=checkEWpn(ri->ewpn)))
5379 718383 ret=(int32_t)(((weapon*)(s))->angle*10000);
5380
5381 718383 break;
5382
5383 case EWPNDEGANGLE:
5384 if(0!=(s=checkEWpn(ri->ewpn)))
5385 {
5386 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
5387 }
5388
5389 break;
5390
5391 case EWPNVX:
5392 if(0!=(s=checkEWpn(ri->ewpn)))
5393 {
5394 if (((weapon*)(s))->angular)
5395 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5396 else
5397 {
5398 switch(NORMAL_DIR(((weapon*)(s))->dir))
5399 {
5400 case l_up:
5401 case l_down:
5402 case left:
5403 ret = int32_t(-10000.0*((weapon*)s)->step);
5404 break;
5405 case r_up:
5406 case r_down:
5407 case right:
5408 ret = int32_t(10000.0*((weapon*)s)->step);
5409 break;
5410
5411 default:
5412 ret = 0;
5413 break;
5414 }
5415 }
5416 }
5417
5418 break;
5419
5420 case EWPNVY:
5421 if(0!=(s=checkEWpn(ri->ewpn)))
5422 {
5423 if (((weapon*)(s))->angular)
5424 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5425 else
5426 {
5427 switch(NORMAL_DIR(((weapon*)(s))->dir))
5428 {
5429 case l_up:
5430 case r_up:
5431 case up:
5432 ret = int32_t(-10000.0*((weapon*)s)->step);
5433 break;
5434 case l_down:
5435 case r_down:
5436 case down:
5437 ret = int32_t(10000.0*((weapon*)s)->step);
5438 break;
5439
5440 default:
5441 ret = 0;
5442 break;
5443 }
5444 }
5445 }
5446
5447 break;
5448
5449
5450 case EWPNANGULAR:
5451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136793 times.
136793 if(0!=(s=checkEWpn(ri->ewpn)))
5452 136793 ret=((weapon*)(s))->angular*10000;
5453
5454 136793 break;
5455
5456 case EWPNAUTOROTATE:
5457 if(0!=(s=checkEWpn(ri->ewpn)))
5458 ret=((weapon*)(s))->autorotate*10000;
5459
5460 break;
5461
5462 case EWPNBEHIND:
5463 if(0!=(s=checkEWpn(ri->ewpn)))
5464 ret=((weapon*)(s))->behind*10000;
5465
5466 break;
5467
5468 case EWPNDRAWTYPE:
5469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46359 times.
46359 if(0!=(s=checkEWpn(ri->ewpn)))
5470 46359 ret=((weapon*)(s))->drawstyle*10000;
5471
5472 46359 break;
5473
5474 case EWPNPOWER:
5475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 90304 times.
90304 if(0!=(s=checkEWpn(ri->ewpn)))
5476 90304 ret=((weapon*)(s))->power*10000;
5477
5478 90304 break;
5479
5480 case EWPNDEAD:
5481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6052 times.
6052 if(0!=(s=checkEWpn(ri->ewpn)))
5482 6052 ret=((weapon*)(s))->dead*10000;
5483
5484 6052 break;
5485
5486 case EWPNID:
5487
2/2
✓ Branch 0 taken 72689 times.
✓ Branch 1 taken 2727389 times.
2800078 if(0!=(s=checkEWpn(ri->ewpn)))
5488 2727389 ret=((weapon*)(s))->id*10000;
5489
5490 2800078 break;
5491
5492 case EWPNTILE:
5493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205013 times.
205013 if(0!=(s=checkEWpn(ri->ewpn)))
5494 205013 ret=((weapon*)(s))->tile*10000;
5495
5496 205013 break;
5497
5498 case EWPNSCRIPTTILE:
5499 if(0!=(s=checkEWpn(ri->ewpn)))
5500 ret=((weapon*)(s))->scripttile*10000;
5501
5502 break;
5503
5504 case EWPNSCRIPTFLIP:
5505 if(0!=(s=checkEWpn(ri->ewpn)))
5506 ret=((weapon*)(s))->scriptflip*10000;
5507
5508 break;
5509
5510 case EWPNCSET:
5511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65315 times.
65315 if(0!=(s=checkEWpn(ri->ewpn)))
5512 65315 ret=((weapon*)(s))->cs*10000;
5513
5514 65315 break;
5515
5516 case EWPNFLASHCSET:
5517 if(0!=(s=checkEWpn(ri->ewpn)))
5518 ret=(((weapon*)(s))->o_cset>>4)*10000;
5519
5520 break;
5521
5522 case EWPNFRAMES:
5523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5524 96 ret=((weapon*)(s))->frames*10000;
5525
5526 96 break;
5527
5528 case EWPNFRAME:
5529 if(0!=(s=checkEWpn(ri->ewpn)))
5530 ret=((weapon*)(s))->aframe*10000;
5531
5532 break;
5533
5534 case EWPNASPEED:
5535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5536 96 ret=((weapon*)(s))->o_speed*10000;
5537
5538 96 break;
5539
5540 case EWPNFLASH:
5541 if(0!=(s=checkEWpn(ri->ewpn)))
5542 ret=((weapon*)(s))->flash*10000;
5543
5544 break;
5545
5546 case EWPNFLIP:
5547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12006 times.
12006 if(0!=(s=checkEWpn(ri->ewpn)))
5548 12006 ret=((weapon*)(s))->flip*10000;
5549
5550 12006 break;
5551
5552 case EWPNROTATION:
5553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if ( get_qr(qr_OLDSPRITEDRAWS) )
5554 {
5555 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
5556 break;
5557 }
5558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(0!=(s=checkEWpn(ri->ewpn)))
5559 218 ret=((weapon*)(s))->rotation*10000;
5560
5561 218 break;
5562
5563 case EWPNCOUNT:
5564 6012426 ret=Ewpns.Count()*10000;
5565 6012426 break;
5566
5567 case EWPNEXTEND:
5568 if(0!=(s=checkEWpn(ri->ewpn)))
5569 ret=((weapon*)(s))->extend*10000;
5570
5571 break;
5572
5573 case EWPNOTILE:
5574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10477 times.
10477 if(0!=(s=checkEWpn(ri->ewpn)))
5575 10477 ret=((weapon*)(s))->o_tile*10000;
5576
5577 10477 break;
5578
5579 case EWPNOCSET:
5580 if(0!=(s=checkEWpn(ri->ewpn)))
5581 ret=(((weapon*)(s))->o_cset&15)*10000;
5582
5583 break;
5584
5585 case EWPNHXOFS:
5586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157773 times.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5587 157773 ret=(((weapon*)(s))->hxofs)*10000;
5588
5589 157773 break;
5590
5591 case EWPNHYOFS:
5592
1/2
✓ Branch 0 taken 157773 times.
✗ Branch 1 not taken.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5593 157773 ret=(((weapon*)(s))->hyofs)*10000;
5594
5595 157773 break;
5596
5597 case EWPNXOFS:
5598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48464 times.
48464 if(0!=(s=checkEWpn(ri->ewpn)))
5599 48464 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
5600
5601 48464 break;
5602
5603 case EWPNYOFS:
5604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 if(0!=(s=checkEWpn(ri->ewpn)))
5605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5606
5607 60558 break;
5608
5609 case EWPNSHADOWXOFS:
5610 if(0!=(s=checkEWpn(ri->ewpn)))
5611 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5612
5613 break;
5614
5615 case EWPNSHADOWYOFS:
5616 if(0!=(s=checkEWpn(ri->ewpn)))
5617 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5618
5619 break;
5620 case EWPNTOTALDYOFFS:
5621 if(0!=(s=checkEWpn(ri->ewpn)))
5622 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5623 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5624 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0) * 10000);
5625 break;
5626
5627 case EWPNZOFS:
5628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1880 times.
1880 if(0!=(s=checkEWpn(ri->ewpn)))
5629 1880 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5630
5631 1880 break;
5632
5633 case EWPNHXSZ:
5634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149564 times.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5635 149564 ret=(((weapon*)(s))->hit_width)*10000;
5636
5637 149564 break;
5638
5639 case EWPNHYSZ:
5640
1/2
✓ Branch 0 taken 149564 times.
✗ Branch 1 not taken.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5641 149564 ret=(((weapon*)(s))->hit_height)*10000;
5642
5643 149564 break;
5644
5645 case EWPNHZSZ:
5646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81355 times.
81355 if(0!=(s=checkEWpn(ri->ewpn)))
5647 81355 ret=(((weapon*)(s))->hzsz)*10000;
5648
5649 81355 break;
5650
5651 case EWPNTXSZ:
5652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125257 times.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5653 125257 ret=(((weapon*)(s))->txsz)*10000;
5654
5655 125257 break;
5656
5657 case EWPNTYSZ:
5658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125257 times.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5659 125257 ret=(((weapon*)(s))->tysz)*10000;
5660
5661 125257 break;
5662
5663 case EWPNCOLLDET:
5664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10565 times.
10565 if(0!=(s=checkEWpn(ri->ewpn)))
5665 10565 ret=(((weapon*)(s))->scriptcoldet)*10000;
5666
5667 10565 break;
5668
5669 case EWPNENGINEANIMATE:
5670 if(0!=(s=checkEWpn(ri->ewpn)))
5671 ret=(((weapon*)(s))->do_animation)*10000;
5672
5673 break;
5674
5675 case EWPNPARENT:
5676 if(0!=(s=checkEWpn(ri->ewpn)))
5677 ret= ((get_qr(qr_OLDEWPNPARENT)) ? (((weapon*)(s))->parentid)*10000 : (((weapon*)(s))->parentid));
5678
5679 break;
5680
5681 case EWEAPONSCRIPTUID:
5682 if(0!=(s=checkEWpn(ri->ewpn)))
5683 ret=(((weapon*)(s))->getUID());
5684
5685 break;
5686
5687 case EWPNPARENTUID:
5688 if(0!=(s=checkEWpn(ri->ewpn)))
5689 ret = s->parent ? s->parent->getUID() : 0;
5690
5691 break;
5692
5693 case EWPNSCRIPT:
5694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(0!=(s=checkEWpn(ri->ewpn)))
5695 43 ret=(((weapon*)(s))->script)*10000;
5696
5697 43 break;
5698
5699 case EWPNFALLCLK:
5700 if(0!=(s=checkEWpn(ri->ewpn)))
5701 {
5702 ret = ((weapon*)(s))->fallclk * 10000;
5703 }
5704 break;
5705
5706 case EWPNFALLCMB:
5707 if(0!=(s=checkEWpn(ri->ewpn)))
5708 {
5709 ret = ((weapon*)(s))->fallCombo * 10000;
5710 }
5711 break;
5712
5713 case EWPNDROWNCLK:
5714 if(0!=(s=checkEWpn(ri->ewpn)))
5715 {
5716 ret = ((weapon*)(s))->drownclk * 10000;
5717 }
5718 break;
5719
5720 case EWPNDROWNCMB:
5721 if(0!=(s=checkEWpn(ri->ewpn)))
5722 {
5723 ret = ((weapon*)(s))->drownCombo * 10000;
5724 }
5725 break;
5726 case EWPNFAKEZ:
5727 if(0!=(s=checkEWpn(ri->ewpn)))
5728 {
5729 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5730 {
5731 ret=(((weapon*)(s))->fakez).getZLong();
5732 }
5733 else
5734 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5735 }
5736 break;
5737
5738 case EWPNGLOWRAD:
5739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30735 times.
30735 if(0!=(s=checkEWpn(ri->ewpn)))
5740 {
5741 30735 ret = ((weapon*)(s))->glowRad * 10000;
5742 30735 }
5743 30735 break;
5744
5745 case EWPNGLOWSHP:
5746 if(0!=(s=checkEWpn(ri->ewpn)))
5747 {
5748 ret = ((weapon*)(s))->glowShape * 10000;
5749 }
5750 break;
5751
5752 case EWPNUNBL:
5753 if(0!=(s=checkEWpn(ri->ewpn)))
5754 {
5755 ret = ((weapon*)(s))->unblockable * 10000;
5756 }
5757 break;
5758
5759 case EWPNSHADOWSPR:
5760 if(0!=(s=checkEWpn(ri->ewpn)))
5761 {
5762 ret = ((weapon*)(s))->spr_shadow * 10000;
5763 }
5764 break;
5765 case EWSWHOOKED:
5766 if(0!=(s=checkEWpn(ri->ewpn)))
5767 {
5768 ret = s->switch_hooked ? 10000 : 0;
5769 }
5770 break;
5771 case EWPNTIMEOUT:
5772 if(0!=(s=checkEWpn(ri->ewpn)))
5773 {
5774 ret = ((weapon*)(s))->weap_timeout * 10000;
5775 }
5776 break;
5777 case EWPNDEATHITEM:
5778 if(0!=(s=checkEWpn(ri->ewpn)))
5779 {
5780 ret = ((weapon*)(s))->death_spawnitem * 10000;
5781 }
5782 break;
5783 case EWPNDEATHDROPSET:
5784 if(0!=(s=checkEWpn(ri->ewpn)))
5785 {
5786 ret = ((weapon*)(s))->death_spawndropset * 10000;
5787 }
5788 break;
5789 case EWPNDEATHIPICKUP:
5790 if(0!=(s=checkEWpn(ri->ewpn)))
5791 {
5792 ret = ((weapon*)(s))->death_item_pflags * 10000;
5793 }
5794 break;
5795 case EWPNDEATHSPRITE:
5796 if(0!=(s=checkEWpn(ri->ewpn)))
5797 {
5798 ret = ((weapon*)(s))->death_sprite * 10000;
5799 }
5800 break;
5801 case EWPNDEATHSFX:
5802 if(0!=(s=checkEWpn(ri->ewpn)))
5803 {
5804 ret = ((weapon*)(s))->death_sfx * 10000;
5805 }
5806 break;
5807 case EWPNLIFTLEVEL:
5808 if(0!=(s=checkEWpn(ri->ewpn)))
5809 {
5810 ret = ((weapon*)(s))->lift_level * 10000;
5811 }
5812 break;
5813 case EWPNLIFTTIME:
5814 if(0!=(s=checkEWpn(ri->ewpn)))
5815 {
5816 ret = ((weapon*)(s))->lift_time * 10000;
5817 }
5818 break;
5819 case EWPNLIFTHEIGHT:
5820 if(0!=(s=checkEWpn(ri->ewpn)))
5821 {
5822 ret = ((weapon*)(s))->lift_height.getZLong();
5823 }
5824 break;
5825
5826 case GETPIXEL:
5827 ret=FFCore.do_getpixel();
5828 break;
5829
5830 case SCREENSCRDATASIZE:
5831 {
5832 int index = map_screen_index(cur_map, ri->screenref);
5833 if (index < 0) break;
5834 ret = 10000*game->scriptDataSize(index);
5835 break;
5836 }
5837
5838 case DISTANCE:
5839 {
5840 792465 double x1 = double(ri->d[rSFTEMP] / 10000.0);
5841 792465 double y1 = double(ri->d[rINDEX] / 10000.0);
5842 792465 double x2 = double(ri->d[rINDEX2] / 10000.0);
5843 792465 double y2 = double(ri->d[rEXP1] / 10000.0);
5844
5845
5846
5847 792465 int32_t result = FFCore.Distance(x1, y1, x2, y2);
5848 792465 ret = (result);
5849
5850 792465 break;
5851 }
5852 case LONGDISTANCE:
5853 {
5854 double x1 = double(ri->d[rSFTEMP]);
5855 double y1 = double(ri->d[rINDEX]);
5856 double x2 = double(ri->d[rINDEX2]);
5857 double y2 = double(ri->d[rEXP1]);
5858
5859
5860
5861 int32_t result = FFCore.LongDistance(x1, y1, x2, y2);
5862 ret = (result);
5863
5864 break;
5865 }
5866
5867 case DISTANCESCALE:
5868 {
5869 double x1 = (double)(ri->d[rSFTEMP] / 10000.0);
5870 double y1 = (double)(ri->d[rINDEX] / 10000.0);
5871 double x2 = (double)(ri->d[rINDEX2] / 10000.0);
5872 double y2 = (double)(ri->d[rEXP1] / 10000.0);
5873
5874 int32_t scale = (ri->d[rWHAT_NO_7]/10000);
5875
5876 if ( !scale ) scale = 10000;
5877 int32_t result = FFCore.Distance(x1, y1, x2, y2, scale);
5878 ret = (result);
5879
5880 break;
5881 }
5882 case LONGDISTANCESCALE:
5883 {
5884 double x1 = (double)(ri->d[rSFTEMP]);
5885 double y1 = (double)(ri->d[rINDEX]);
5886 double x2 = (double)(ri->d[rINDEX2]);
5887 double y2 = (double)(ri->d[rEXP1]);
5888
5889 int32_t scale = (ri->d[rWHAT_NO_7]);
5890
5891 if ( !scale ) scale = 1;
5892 int32_t result = FFCore.LongDistance(x1, y1, x2, y2, scale);
5893 ret = (result);
5894
5895 break;
5896 }
5897
5898 // Note: never used?
5899 case GAMEGUYCOUNTD:
5900 {
5901 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
5902 ret = game->guys[mi] * 10000;
5903 break;
5904 }
5905
5906 case ALLOCATEBITMAPR:
5907 225 ret=FFCore.get_free_bitmap();
5908 225 break;
5909
5910 case GETMIDI:
5911 63717 ret=(currmidi-(ZC_MIDI_COUNT-1))*10000;
5912 63717 break;
5913
5914 case CURDSCR:
5915 {
5916 11271214 int32_t di = (get_currscr()-DMaps[get_currdmap()].xoff);
5917
2/2
✓ Branch 0 taken 4461159 times.
✓ Branch 1 taken 6810055 times.
11271214 ret=(DMaps[get_currdmap()].type==dmOVERW ? cur_screen : di)*10000;
5918 }
5919 11271214 break;
5920
5921 case GAMEMAXMAPS:
5922 96 ret = (map_count)*10000;
5923 96 break;
5924 case GAMENUMMESSAGES:
5925 ret = (msg_count-1) * 10000;
5926 break;
5927
5928 case CURDMAP:
5929 58184250 ret=cur_dmap*10000;
5930 58184250 break;
5931
5932 case CURLEVEL:
5933 15080301 ret=DMaps[get_currdmap()].level*10000;
5934 15080301 break;
5935
5936 case GAMECLICKFREEZE:
5937 ret=disableClickToFreeze?0:10000;
5938 break;
5939
5940
5941 case NOACTIVESUBSC:
5942 ret=Hero.stopSubscreenFalling()?10000:0;
5943 break;///----------------------------------------------------------------------------------------------------//
5944 //BottleTypes
5945
5946 case BOTTLENEXT:
5947 {
5948 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
5949 {
5950 ret = 10000L * ptr->next_type;
5951 }
5952 else ret = -10000L;
5953 }
5954 break;
5955
5956 ///----------------------------------------------------------------------------------------------------//
5957 //Region
5958
5959 case REGION_WIDTH:
5960 {
5961 47264 ret = world_w * 10000;
5962 }
5963 47264 break;
5964
5965 case REGION_HEIGHT:
5966 {
5967 39568 ret = world_h * 10000;
5968 }
5969 39568 break;
5970
5971 case REGION_SCREEN_WIDTH:
5972 {
5973 64 ret = cur_region.screen_width * 10000;
5974 }
5975 64 break;
5976
5977 case REGION_SCREEN_HEIGHT:
5978 {
5979 20 ret = cur_region.screen_height * 10000;
5980 }
5981 20 break;
5982
5983 case REGION_NUM_COMBOS:
5984 {
5985 32 ret = region_num_rpos * 10000;
5986 }
5987 32 break;
5988
5989 case REGION_ID:
5990 {
5991 982758 ret = get_current_region_id() * 10000;
5992 }
5993 982758 break;
5994
5995 case REGION_ORIGIN_SCREEN:
5996 {
5997 ret = cur_screen;
5998 }
5999 break;
6000
6001 ///----------------------------------------------------------------------------------------------------//
6002 //Viewport
6003
6004 case VIEWPORT_TARGET:
6005 {
6006 ret = get_viewport_sprite()->uid;
6007 }
6008 break;
6009
6010 case VIEWPORT_MODE:
6011 {
6012 ret = (int)viewport_mode;
6013 }
6014 break;
6015
6016 case VIEWPORT_X:
6017 {
6018 24940 ret = viewport.x * 10000;
6019 }
6020 24940 break;
6021
6022 case VIEWPORT_Y:
6023 {
6024 21112 ret = viewport.y * 10000;
6025 }
6026 21112 break;
6027
6028 case VIEWPORT_WIDTH:
6029 {
6030 8014 ret = viewport.w * 10000;
6031 }
6032 8014 break;
6033
6034 case VIEWPORT_HEIGHT:
6035 {
6036 11842 ret = viewport.h * 10000;
6037 }
6038 11842 break;
6039
6040 ///----------------------------------------------------------------------------------------------------//
6041 //Screen Information
6042
6043 #define GET_SCREENDATA_VAR_INT32(member) \
6044 { \
6045 ret = (get_scr(ri->screenref)->member *10000); \
6046 } \
6047
6048 #define GET_SCREENDATA_VAR_INT16(member) \
6049 { \
6050 ret = (get_scr(ri->screenref)->member *10000); \
6051 } \
6052
6053 #define GET_SCREENDATA_VAR_BYTE(member) \
6054 { \
6055 ret = (get_scr(ri->screenref)->member *10000); \
6056 } \
6057
6058 #define GET_SCREENDATA_BYTE_INDEX(member, indexbound) \
6059 { \
6060 int32_t indx = ri->d[rINDEX] / 10000; \
6061 ret = (get_scr(ri->screenref)->member[indx] *10000); \
6062 } \
6063
6064 //byte
6065 #define GET_SCREENDATA_LAYER_INDEX(member, indexbound) \
6066 { \
6067 int32_t indx = ri->d[rINDEX] / 10000; \
6068 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
6069 { \
6070 ret = -10000; \
6071 } \
6072 else \
6073 { \
6074 ret = (get_scr(ri->screenref)->member[indx-1] *10000); \
6075 } \
6076 } \
6077
6078 #define GET_SCREENDATA_BOOL_INDEX(member, indexbound) \
6079 { \
6080 int32_t indx = ri->d[rINDEX] / 10000; \
6081 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
6082 { \
6083 ret = -10000; \
6084 } \
6085 else \
6086 { \
6087 ret = (get_scr(ri->screenref)->member[indx]?10000:0); \
6088 } \
6089 } \
6090
6091
6092 #define GET_SCREENDATA_FLAG(member, str, indexbound) \
6093 { \
6094 int32_t flag = (value/10000); \
6095 ret = (get_scr(ri->screenref)->member&flag) ? 10000 : 0); \
6096 } \
6097
6098 case SCREENDATAVALID: GET_SCREENDATA_VAR_BYTE(valid); break; //b
6099 case SCREENDATAGUY: GET_SCREENDATA_VAR_BYTE(guy); break; //b
6100 case SCREENDATASTRING: GET_SCREENDATA_VAR_INT32(str); break; //w
6101 case SCREENDATAROOM: GET_SCREENDATA_VAR_BYTE(room); break; //b
6102 case SCREENDATAITEM:
6103 {
6104 mapscr* scr = get_scr(ri->screenref);
6105 if(scr->hasitem)
6106 ret = (scr->item *10000);
6107 else ret = -10000;
6108 break;
6109 }
6110 case SCREENDATAHASITEM: GET_SCREENDATA_VAR_BYTE(hasitem); break; //b
6111 case SCREENDATADOORCOMBOSET: GET_SCREENDATA_VAR_INT32(door_combo_set); break; //w
6112 case SCREENDATAWARPRETURNC: GET_SCREENDATA_VAR_INT32(warpreturnc); break; //w
6113 case SCREENDATASTAIRX: GET_SCREENDATA_VAR_BYTE(stairx); break; //b
6114 case SCREENDATASTAIRY: GET_SCREENDATA_VAR_BYTE(stairy); break; //b
6115 case SCREENDATAITEMX: GET_SCREENDATA_VAR_BYTE(itemx); break; //itemx
6116 case SCREENDATAITEMY: GET_SCREENDATA_VAR_BYTE(itemy); break; //itemy
6117 1026 case SCREENDATACOLOUR: GET_SCREENDATA_VAR_INT32(color); break; //w
6118 case SCREENDATAENEMYFLAGS: GET_SCREENDATA_VAR_BYTE(flags11); break; //b
6119 // Note: never used?
6120 case SCREENDATADOOR: GET_SCREENDATA_BYTE_INDEX(door, 3); break; //b, 4 of these
6121 case SCREENDATAEXITDIR: GET_SCREENDATA_VAR_BYTE(exitdir); break; //b
6122 case SCREENDATAPATTERN: GET_SCREENDATA_VAR_BYTE(pattern); break; //b
6123 case SCREENDATAWARPARRIVALX: GET_SCREENDATA_VAR_BYTE(warparrivalx); break; //b
6124 case SCREENDATAWARPARRIVALY: GET_SCREENDATA_VAR_BYTE(warparrivaly); break; //b
6125 case SCREENDATASIDEWARPINDEX: GET_SCREENDATA_VAR_BYTE(sidewarpindex); break; //b
6126 case SCREENDATAUNDERCOMBO: GET_SCREENDATA_VAR_INT32(undercombo); break; //w
6127 case SCREENDATAUNDERCSET: GET_SCREENDATA_VAR_BYTE(undercset); break; //b
6128 case SCREENDATACATCHALL: GET_SCREENDATA_VAR_INT32(catchall); break; //W
6129
6130 case SCREENDATACSENSITIVE: GET_SCREENDATA_VAR_BYTE(csensitive); break; //B
6131 case SCREENDATANORESET: GET_SCREENDATA_VAR_INT32(noreset); break; //W
6132 case SCREENDATANOCARRY: GET_SCREENDATA_VAR_INT32(nocarry); break; //W
6133 case SCREENDATATIMEDWARPTICS: GET_SCREENDATA_VAR_INT32(timedwarptics); break; //W
6134 case SCREENDATANEXTMAP: GET_SCREENDATA_VAR_BYTE(nextmap); break; //B
6135 case SCREENDATANEXTSCREEN: GET_SCREENDATA_VAR_BYTE(nextscr); break; //B
6136 case SCREENDATAVIEWX: break;//GET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
6137 case SCREENDATAVIEWY: break;//GET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
6138 case SCREENDATASCREENWIDTH: break;//GET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
6139 case SCREENDATASCREENHEIGHT: break;//GET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
6140 case SCREENDATAENTRYX: GET_SCREENDATA_VAR_BYTE(entry_x); break; //B
6141 case SCREENDATAENTRYY: GET_SCREENDATA_VAR_BYTE(entry_y); break; //B
6142 //Number of ffcs that are in use (have valid data
6143 // Note: that is totally not what its doing.
6144 case SCREENDATANUMFF:
6145 {
6146 int id = ri->d[rINDEX] / 10000;
6147 if (auto ffc = ResolveFFCWithID(id))
6148 ret = ffc->data != 0 ? 10000 : 0;
6149 break;
6150 }
6151
6152 // Note: never used?
6153 case SCREENDATAFFINITIALISED: {
6154 int32_t indx = ri->d[rINDEX] / 10000;
6155 if (indx < 0 || indx > MAX_FFCID)
6156 {
6157 scripting_log_error_with_context("Invalid index: %d", (indx));
6158 ret = -10000;
6159 }
6160 else
6161 {
6162 ret = get_script_engine_data(ScriptType::FFC, indx).initialized ? 10000 : 0;
6163 }
6164 }
6165 break;
6166
6167 case SCREENDATASCRIPTENTRY:
6168 {
6169 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
6170 ret = -10000;
6171 }
6172 break;
6173 case SCREENDATASCRIPTOCCUPANCY:
6174 {
6175 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
6176 ret = -10000;
6177 }
6178 break;
6179 case SCREENDATASCRIPTEXIT:
6180 {
6181 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
6182 ret = -10000;
6183 }
6184 break;
6185
6186 case SCREENDATAOCEANSFX: GET_SCREENDATA_VAR_BYTE(oceansfx); break; //B
6187 case SCREENDATABOSSSFX: GET_SCREENDATA_VAR_BYTE(bosssfx); break; //B
6188 17 case SCREENDATASECRETSFX: GET_SCREENDATA_VAR_BYTE(secretsfx); break; //B
6189 case SCREENDATAHOLDUPSFX: GET_SCREENDATA_VAR_BYTE(holdupsfx); break; //B
6190 case SCREENDATASCREENMIDI:
6191 {
6192 ret = ((get_scr(ri->screenref)->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
6193 break;
6194 }
6195 case SCREENDATALENSLAYER: GET_SCREENDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
6196
6197 case SCREENSECRETSTRIGGERED:
6198 {
6199 910 ret = get_screen_state(ri->screenref).triggered_secrets ? 10000L : 0L;
6200 910 break;
6201 }
6202
6203 case SCREENDATAGUYCOUNT:
6204 {
6205 int mi = mapind(cur_map, ri->screenref);
6206 if(mi < 0)
6207 ret = -10000;
6208 else ret = game->guys[mi] * 10000;
6209 break;
6210 }
6211 case SCREENDATAEXDOOR:
6212 {
6213 ret = 0;
6214 int mi = mapind(cur_map, ri->screenref);
6215 if(mi < 0) break;
6216 int dir = SH::read_stack(ri->sp+1) / 10000;
6217 int ind = SH::read_stack(ri->sp+0) / 10000;
6218 if(unsigned(dir) > 3)
6219 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->GetExDoor()'; must be 0-3\n", dir);
6220 else if(unsigned(ind) > 7)
6221 Z_scripterrlog("Invalid index '%d' passed to 'Screen->GetExDoor()'; must be 0-7\n", ind);
6222 else
6223 {
6224 int bit = 1<<ind;
6225 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
6226 }
6227 break;
6228 }
6229
6230 case SHOWNMSG:
6231 {
6232
4/4
✓ Branch 0 taken 1832 times.
✓ Branch 1 taken 7660 times.
✓ Branch 2 taken 1800 times.
✓ Branch 3 taken 32 times.
9492 ret = ((msg_active || msg_onscreen) ? msgstr : 0) * 10000L;
6233 9492 break;
6234 }
6235
6236 case SDDD:
6237 43250 ret=FFScript::get_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2] / 10000);
6238 43250 break;
6239
6240 case LINKOTILE:
6241 ret=FFCore.getHeroOTile(ri->d[rINDEX]/10000, ri->d[rINDEX2] / 10000);
6242 break;
6243
6244 case SDDDD:
6245 6 ret=FFScript::get_screen_d(ri->d[rINDEX2] / 10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1] / 10000);
6246 6 break;
6247
6248 case SCREENSCRIPT:
6249 ret=get_scr(ri->screenref)->script*10000;
6250 break;
6251
6252 //These use the same method as GetScreenD -Z
6253 case SCREENWIDTH:
6254 // ret=FFScript::get_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6255 break;
6256
6257 case SCREENHEIGHT:
6258 // ret=FFScript::get_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6259 break;
6260
6261 case SCREENVIEWX:
6262 // ret=get_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6263 break;
6264
6265 case SCREENVIEWY:
6266 // ret=get_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6267 break;
6268
6269 case LIT:
6270 10246 ret= get_lights() ? 10000 : 0;
6271 10246 break;
6272
6273 case WAVY:
6274 7214 ret = wavy*10000;
6275 7214 break;
6276
6277 case QUAKE:
6278 2391 ret = quakeclk*10000;
6279 2391 break;
6280
6281 case NPCCOUNT:
6282 25369944 ret = guys.Count()*10000;
6283 25369944 break;
6284
6285 case ROOMDATA:
6286 47 ret = get_scr(ri->screenref)->catchall*10000;
6287 47 break;
6288
6289 case ROOMTYPE:
6290 2 ret = get_scr(ri->screenref)->room*10000;
6291 2 break;
6292
6293 case PUSHBLOCKX:
6294
2/2
✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 339575 times.
343159 ret = mblock2.active() ? int32_t(mblock2.x)*10000 : -10000;
6295 343159 break;
6296
6297 case PUSHBLOCKY:
6298
2/2
✓ Branch 0 taken 2943 times.
✓ Branch 1 taken 98007 times.
100950 ret = mblock2.active() ? int32_t(mblock2.y)*10000 : -10000;
6299 100950 break;
6300
6301 case PUSHBLOCKLAYER:
6302 ret = mblock2.active() ? int32_t(mblock2.blockLayer)*10000 : -10000;
6303 break;
6304
6305 case PUSHBLOCKCOMBO:
6306 ret = mblock2.bcombo*10000;
6307 break;
6308
6309 case PUSHBLOCKCSET:
6310 ret = mblock2.cs*10000;
6311 break;
6312
6313 case UNDERCOMBO:
6314 1636 ret = get_scr(ri->screenref)->undercombo*10000;
6315 1636 break;
6316
6317 case UNDERCSET:
6318 1610 ret = get_scr(ri->screenref)->undercset*10000;
6319 1610 break;
6320
6321 case SCREEN_INDEX:
6322 32 ret = ri->screenref*10000;
6323 32 break;
6324
6325 case SCREEN_DRAW_ORIGIN:
6326 ret = (int)ri->screen_draw_origin;
6327 break;
6328
6329 case SCREEN_DRAW_ORIGIN_TARGET:
6330 ret = ri->screen_draw_origin_target;
6331 break;
6332
6333 //Creates an lweapon using an iemdata struct values to generate its properties.
6334 //Useful in conjunction with the new weapon editor.
6335 case CREATELWPNDX:
6336 {
6337 //Z_message("Trying to get Hero->SetExtend().\n");
6338 int32_t ID = (ri->d[rINDEX] / 10000);
6339 int32_t itemid = (ri->d[rINDEX2]/10000);
6340 itemid = vbound(itemid,0,(MAXITEMS-1));
6341
6342 // TODO: use has_space()
6343 if ( Lwpns.Count() < 256 )
6344 {
6345
6346 (void)Lwpns.add
6347 (
6348 new weapon
6349 (
6350 (zfix)0, /*X*/
6351 (zfix)0, /*Y*/
6352 (zfix)0, /*Z*/
6353 ID, /*id*/
6354 0, /*type*/
6355 0, /*power*/
6356 0, /*dir*/
6357 -1, /*Parentid*/
6358 Hero.getUID(), /*prntid*/
6359 false, /*isdummy*/
6360 1, /*script_gen*/
6361 1, /*islwpn*/
6362 (ID==wWind?1:0) /*special*/
6363 )
6364 );
6365 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
6366
6367 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
6368 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //What the fuck Zoria, this broke old quests...
6369 w->ScriptGenerated = 1;
6370 w->isLWeapon = 1;
6371 if(ID == wWind) w->specialinfo = 1;
6372 //weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
6373 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //not needed here because this has access to wpn->prent
6374 }
6375 else
6376 {
6377 Z_scripterrlog("Tried to create too many LWeapons on the screen. The current LWeapon count is: %d\n", Lwpns.Count());
6378 ri->lwpn = 0;
6379 }
6380
6381 ret = ri->lwpn;
6382 }
6383 break;
6384
6385 ///----------------------------------------------------------------------------------------------------//
6386 //New Datatype Variables
6387
6388 ///----------------------------------------------------------------------------------------------------//
6389 //spritedata sp-> Variables
6390
6391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATATILE: GET_SPRITEDATA_VAR_INT(tile) break;
6392 case SPRITEDATAMISC: GET_SPRITEDATA_VAR_INT(misc) break;
6393 case SPRITEDATACSETS:
6394 {
6395
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (auto sd = checkSpriteData(ri->spritedataref); !sd)
6396 ret = -10000;
6397 else
6398 16 ret = ((sd->csets & 0xF) * 10000);
6399 16 break;
6400 }
6401 case SPRITEDATAFLCSET:
6402 {
6403 if (auto sd = checkSpriteData(ri->spritedataref); !sd)
6404 ret = -10000;
6405 else
6406 ret = (((sd->csets & 0xF0)>>4) * 10000);
6407 break;
6408 }
6409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATAFRAMES: GET_SPRITEDATA_VAR_INT(frames) break;
6410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATASPEED: GET_SPRITEDATA_VAR_INT(speed) break;
6411 case SPRITEDATATYPE: GET_SPRITEDATA_VAR_INT(type) break;
6412 case SPRITEDATAID:
6413 {
6414 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
6415 {
6416 ret = -10000;
6417 Z_scripterrlog("Invalid Sprite ID passed to spritedata->ID: %d\n", (ri->spritedataref*10000));
6418 break;
6419 }
6420 ret = ri->spritedataref*10000;
6421 break;
6422 }
6423
6424 ///----------------------------------------------------------------------------------------------------//
6425 //mapdata m-> variables
6426 #define GET_MAPDATA_VAR_INT32(member) \
6427 { \
6428 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6429 { \
6430 ret = (m->member *10000); \
6431 } \
6432 else \
6433 { \
6434 ret = -10000; \
6435 } \
6436 } \
6437
6438 #define GET_MAPDATA_VAR_INT16(member) \
6439 { \
6440 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6441 { \
6442 ret = (m->member *10000); \
6443 } \
6444 else \
6445 { \
6446 ret = -10000; \
6447 } \
6448 } \
6449
6450 #define GET_MAPDATA_VAR_BYTE(member) \
6451 { \
6452 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6453 { \
6454 ret = (m->member *10000); \
6455 } \
6456 else \
6457 { \
6458 ret = -10000; \
6459 } \
6460 } \
6461
6462 #define GET_MAPDATA_FLAG(member) \
6463 { \
6464 int32_t flag = (value/10000); \
6465 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
6466 { \
6467 ret = (m->member&flag) ? 10000 : 0); \
6468 } \
6469 else \
6470 { \
6471 ret = -10000; \
6472 } \
6473 } \
6474
6475 #define GET_MAPDATA_FFCPOS_INDEX32(member, indexbound) \
6476 { \
6477 int32_t index = (ri->d[rINDEX] / 10000); \
6478 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6479 { \
6480 ret = (handle.ffc->member).getZLong(); \
6481 } \
6482 else \
6483 { \
6484 ret = -10000; \
6485 } \
6486 } \
6487
6488 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
6489 { \
6490 int32_t index = (ri->d[rINDEX] / 10000); \
6491 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6492 { \
6493 ret = (handle.ffc->member)*10000; \
6494 } \
6495 else \
6496 { \
6497 ret = -10000; \
6498 } \
6499 } \
6500
6501 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
6502 { \
6503 int32_t index = (ri->d[rINDEX] / 10000); \
6504 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6505 { \
6506 ret = (handle.ffc->member)*10000; \
6507 } \
6508 else \
6509 { \
6510 ret = -10000; \
6511 } \
6512 } \
6513
6514 case LOADMAPDATA:
6515 6567172 ret=FFScript::loadMapData();
6516 6567172 break;
6517
6518 case CREATEBITMAP:
6519 {
6520 3858 ret=FFCore.do_create_bitmap();
6521 3858 break;
6522 }
6523
6524
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 case MAPDATAVALID: GET_MAPDATA_VAR_BYTE(valid); break; //b
6525 case MAPDATAGUY: GET_MAPDATA_VAR_BYTE(guy); break; //b
6526 case MAPDATASTRING: GET_MAPDATA_VAR_INT32(str); break; //w
6527 case MAPDATAROOM: GET_MAPDATA_VAR_BYTE(room); break; //b
6528 case MAPDATAITEM:
6529 {
6530 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) )
6531 {
6532 if(m->hasitem)
6533 ret = (m->item *10000);
6534 else ret = -10000;
6535 }
6536 else
6537 {
6538 ret = -10000;
6539 }
6540 break;
6541 }
6542 case MAPDATAREGIONID:
6543 {
6544 if (auto scr = ResolveMapdataScr(ri->mapsref))
6545 ret = get_region_id(scr->map, scr->screen) * 10000;
6546 break;
6547 }
6548 case MAPDATAHASITEM: GET_MAPDATA_VAR_BYTE(hasitem); break; //b
6549 case MAPDATADOORCOMBOSET: GET_MAPDATA_VAR_INT32(door_combo_set); break; //w
6550 case MAPDATAWARPRETURNC: GET_MAPDATA_VAR_INT32(warpreturnc); break; //w
6551 case MAPDATASTAIRX: GET_MAPDATA_VAR_BYTE(stairx); break; //b
6552 case MAPDATASTAIRY: GET_MAPDATA_VAR_BYTE(stairy); break; //b
6553 case MAPDATAITEMX: GET_MAPDATA_VAR_BYTE(itemx); break; //itemx
6554 case MAPDATAITEMY: GET_MAPDATA_VAR_BYTE(itemy); break; //itemy
6555
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 case MAPDATACOLOUR: GET_MAPDATA_VAR_INT32(color); break; //w
6556 case MAPDATAENEMYFLAGS: GET_MAPDATA_VAR_BYTE(flags11); break; //b
6557 case MAPDATAEXITDIR: GET_MAPDATA_VAR_BYTE(exitdir); break; //b
6558 case MAPDATAPATTERN: GET_MAPDATA_VAR_BYTE(pattern); break; //b
6559 case MAPDATAWARPARRIVALX: GET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
6560 case MAPDATAWARPARRIVALY: GET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
6561 case MAPDATASIDEWARPINDEX: GET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
6562 case MAPDATAUNDERCOMBO: GET_MAPDATA_VAR_INT32(undercombo); break; //w
6563 case MAPDATAUNDERCSET: GET_MAPDATA_VAR_BYTE(undercset); break; //b
6564 case MAPDATACATCHALL: GET_MAPDATA_VAR_INT32(catchall); break; //W
6565
6566 case MAPDATACSENSITIVE: GET_MAPDATA_VAR_BYTE(csensitive); break; //B
6567 case MAPDATANORESET: GET_MAPDATA_VAR_INT32(noreset); break; //W
6568 case MAPDATANOCARRY: GET_MAPDATA_VAR_INT32(nocarry); break; //W
6569 case MAPDATATIMEDWARPTICS: GET_MAPDATA_VAR_INT32(timedwarptics); break; //W
6570 case MAPDATANEXTMAP: GET_MAPDATA_VAR_BYTE(nextmap); break; //B
6571 case MAPDATANEXTSCREEN: GET_MAPDATA_VAR_BYTE(nextscr); break; //B
6572
6573 case MAPDATAVIEWX: break;//GET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
6574 case MAPDATASCRIPT: GET_MAPDATA_VAR_INT32(script); break; //W
6575 case MAPDATAVIEWY: break;//GET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
6576 case MAPDATASCREENWIDTH: break;//GET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
6577 case MAPDATASCREENHEIGHT: break;//GET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
6578 case MAPDATAENTRYX: GET_MAPDATA_VAR_BYTE(entry_x); break; //B
6579 case MAPDATAENTRYY: GET_MAPDATA_VAR_BYTE(entry_y); break; //B
6580
6581 //Number of ffcs that are in use (have valid data
6582 // NOTE: defunct. Never implemented correctly.
6583 case MAPDATANUMFF:
6584 {
6585 32 int index = ri->d[rINDEX] / 10000;
6586
6587
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
6588 {
6589 32 ret = (handle.data() != 0) ? 10000 : 0;
6590 32 }
6591 else
6592 {
6593 ret = 0;
6594 }
6595 32 break;
6596 }
6597
6598 case MAPDATAINTID: //Same form as SetScreenD()
6599 //SetFFCInitD(ffindex, d, value)
6600 {
6601 2004 int32_t index = (ri->d[rINDEX]/10000);
6602 2004 int32_t d_index = ri->d[rINDEX2]/10000;
6603
6604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2004 times.
2004 if (BC::checkBounds(d_index, 0, 7) != SH::_NoError)
6605 break;
6606
6607
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
6608 2004 ret = handle.ffc->initd[d_index];
6609 else
6610 {
6611 ret = -10000;
6612 }
6613 2004 break;
6614 }
6615
6616 case MAPDATASCRIPTENTRY:
6617 {
6618 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
6619 ret = -10000;
6620 }
6621 break;
6622 case MAPDATASCRIPTOCCUPANCY:
6623 {
6624 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
6625 ret = -10000;
6626 }
6627 break;
6628 case MAPDATASCRIPTEXIT:
6629 {
6630 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
6631 ret = -10000;
6632 }
6633 break;
6634
6635 case MAPDATAOCEANSFX: GET_MAPDATA_VAR_BYTE(oceansfx); break; //B
6636 case MAPDATABOSSSFX: GET_MAPDATA_VAR_BYTE(bosssfx); break; //B
6637 case MAPDATASECRETSFX: GET_MAPDATA_VAR_BYTE(secretsfx); break; //B
6638 case MAPDATAHOLDUPSFX: GET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
6639 case MAPDATASCREENMIDI:
6640 {
6641 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6642 {
6643 ret = ((m->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
6644 }
6645 else
6646 {
6647 ret = -10000;
6648 }
6649 break;
6650 }
6651 case MAPDATALENSLAYER: GET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
6652 case MAPDATAMAP:
6653 {
6654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6655 {
6656 9 ret = getMap(ri->mapsref) * 10000;
6657 9 }
6658 else
6659 {
6660 ret = -10000;
6661 }
6662 9 break;
6663 }
6664 case MAPDATASCREEN:
6665 {
6666
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6667 {
6668 21 ret = getScreen(ri->mapsref) * 10000;
6669 21 }
6670 else
6671 {
6672 ret = -10000;
6673 }
6674 21 break;
6675 }
6676 case MAPDATASCRDATASIZE:
6677 {
6678 ret = -10000;
6679 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6680 {
6681 int index = get_ref_map_index(ri->mapsref);
6682 if (index < 0) break;
6683
6684 ret = 10000*game->scriptDataSize(index);
6685 }
6686 break;
6687 }
6688 case MAPDATAGUYCOUNT:
6689 {
6690 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6691 {
6692 int mi = get_mi(ri->mapsref);
6693 if(mi > -1)
6694 {
6695 ret = game->guys[mi] * 10000;
6696 break;
6697 }
6698 }
6699 ret = -10000;
6700 break;
6701 }
6702 case MAPDATAEXDOOR:
6703 {
6704 ret = 0;
6705 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6706 {
6707 int mi = get_mi(ri->mapsref);
6708 if(mi < 0) break;
6709 int dir = SH::read_stack(ri->sp+1) / 10000;
6710 int ind = SH::read_stack(ri->sp+0) / 10000;
6711 if(unsigned(dir) > 3)
6712 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->GetExDoor()'; must be 0-3\n", dir);
6713 else if(unsigned(ind) > 7)
6714 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->GetExDoor()'; must be 0-7\n", ind);
6715 else
6716 {
6717 int bit = 1<<ind;
6718 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
6719 }
6720 }
6721 break;
6722 }
6723
6724 ///----------------------------------------------------------------------------------------------------//
6725 //shopdata sd-> variables
6726
6727 case SHOPDATATYPE:
6728 {
6729 int32_t ref = ri->shopsref;
6730 if ( ref > NUMINFOSHOPS || ref < 0 ) ret = 0;
6731 else ret = ( ( ref <= NUMSHOPS ) ? 10000 : 20000 );
6732 break;
6733 }
6734
6735 ///----------------------------------------------------------------------------------------------------//
6736 //dmapdata dmd-> variables
6737
6738 //getter
6739 701 case DMAPDATAID: ret = ri->dmapsref*10000; break; //read-only, equal to CurrentDMap
6740
6741 case DMAPDATAMAP: //byte
6742 {
6743 225 ret = ((byte)DMaps[ri->dmapsref].map + 1) * 10000; break;
6744 }
6745 case DMAPDATALEVEL: //word
6746 {
6747 ret = ((word)DMaps[ri->dmapsref].level) * 10000; break;
6748 }
6749 case DMAPDATAOFFSET: //char
6750 {
6751 6 ret = ((char)DMaps[ri->dmapsref].xoff) * 10000; break;
6752 }
6753 case DMAPDATACOMPASS: //byte
6754 {
6755 ret = ((byte)DMaps[ri->dmapsref].compass) * 10000; break;
6756 }
6757 case DMAPDATAPALETTE: //word
6758 {
6759 212 ret = ((word)DMaps[ri->dmapsref].color) * 10000; break;
6760 }
6761 case DMAPSCRIPT: //word
6762 {
6763 19 ret = (DMaps[ri->dmapsref].script) * 10000; break;
6764 }
6765 case DMAPDATAMIDI: //byte
6766 {
6767 ret = (DMaps[ri->dmapsref].midi-MIDIOFFSET_DMAP) * 10000; break;
6768 }
6769 case DMAPDATACONTINUE: //byte
6770 {
6771 ret = ((byte)DMaps[ri->dmapsref].cont) * 10000; break;
6772 }
6773 case DMAPDATATYPE: //byte
6774 {
6775 1124 ret = ((byte)DMaps[ri->dmapsref].type&dmfTYPE) * 10000; break;
6776 }
6777 case DMAPDATASIDEVIEW: //byte
6778 {
6779 1095768 ret = ((DMaps[ri->dmapsref].sideview) ? 10000 : 0); break;
6780 }
6781 case DMAPDATAMUISCTRACK: //byte
6782 {
6783 ret = ((byte)DMaps[ri->dmapsref].tmusictrack) * 10000; break;
6784 }
6785 case DMAPDATASUBSCRA:
6786 {
6787 ret = ((byte)DMaps[ri->dmapsref].active_subscreen) * 10000; break;
6788 }
6789 case DMAPDATASUBSCRP:
6790 {
6791 5120 ret = ((byte)DMaps[ri->dmapsref].passive_subscreen) * 10000; break;
6792 }
6793 case DMAPDATASUBSCRO:
6794 {
6795 ret = ((byte)DMaps[ri->dmapsref].overlay_subscreen) * 10000; break;
6796 }
6797 case DMAPDATAFLAGS: //int32_t
6798 {
6799 ret = (DMaps[ri->dmapsref].flags) * 10000; break;
6800 }
6801 case DMAPDATAMIRRDMAP:
6802 {
6803 ret = (DMaps[ri->dmapsref].mirrorDMap) * 10000; break;
6804 }
6805 case DMAPDATALOOPSTART:
6806 {
6807 ret = (DMaps[ri->dmapsref].tmusic_loop_start); break;
6808 }
6809 case DMAPDATALOOPEND:
6810 {
6811 ret = (DMaps[ri->dmapsref].tmusic_loop_end); break;
6812 }
6813 case DMAPDATAXFADEIN:
6814 {
6815 ret = (DMaps[ri->dmapsref].tmusic_xfade_in * 10000); break;
6816 }
6817 case DMAPDATAXFADEOUT:
6818 {
6819 ret = (DMaps[ri->dmapsref].tmusic_xfade_out * 10000); break;
6820 }
6821 case DMAPDATAINTROSTRINGID:
6822 {
6823 ret = (DMaps[ri->dmapsref].intro_string_id * 10000); break;
6824 }
6825 case MUSICUPDATECOND:
6826 {
6827 ret = ((byte)FFCore.music_update_cond) * 10000; break;
6828 }
6829 case DMAPDATAASUBSCRIPT: //word
6830 {
6831 22016 ret = (DMaps[ri->dmapsref].active_sub_script) * 10000; break;
6832 }
6833 case DMAPDATAMAPSCRIPT: //byte
6834 {
6835 ret = (DMaps[ri->dmapsref].onmap_script) * 10000; break;
6836 }
6837 case DMAPDATAPSUBSCRIPT: //word
6838 {
6839 ret = (DMaps[ri->dmapsref].passive_sub_script) * 10000; break;
6840 }
6841
6842 ///----------------------------------------------------------------------------------------------------//
6843 //messagedata msgd-> variables
6844 case MESSAGEDATANEXT: //W
6845 {
6846 int32_t ID = ri->zmsgref;
6847
6848 if(BC::checkMessage(ID) != SH::_NoError)
6849 {
6850 ret = -10000; break;
6851 }
6852 else
6853 {
6854 ret = ((int32_t)MsgStrings[ID].nextstring) * 10000;
6855 break;
6856 }
6857 }
6858
6859 case MESSAGEDATATILE: //W
6860 {
6861 int32_t ID = ri->zmsgref;
6862
6863 if(BC::checkMessage(ID) != SH::_NoError)
6864 ret = -10000;
6865 else
6866 ret = ((int32_t)MsgStrings[ID].tile) * 10000;
6867 break;
6868 }
6869
6870 case MESSAGEDATACSET: //b
6871 {
6872 int32_t ID = ri->zmsgref;
6873
6874 if(BC::checkMessage(ID) != SH::_NoError)
6875 ret = -10000;
6876 else
6877 ret = ((int32_t)MsgStrings[ID].cset) * 10000;
6878 break;
6879 }
6880 case MESSAGEDATATRANS: //BOOL
6881 {
6882 int32_t ID = ri->zmsgref;
6883
6884 if(BC::checkMessage(ID) != SH::_NoError)
6885 ret = -10000;
6886 else
6887 ret = ((MsgStrings[ID].trans)?10000:0);
6888 break;
6889 }
6890 case MESSAGEDATAFONT: //B
6891 {
6892 int32_t ID = ri->zmsgref;
6893
6894 if(BC::checkMessage(ID) != SH::_NoError)
6895 ret = -10000;
6896 else
6897 ret = (int32_t)MsgStrings[ID].font * 10000;
6898 break;
6899 }
6900 case MESSAGEDATAX: //SHORT
6901 {
6902 int32_t ID = ri->zmsgref;
6903
6904 if(BC::checkMessage(ID) != SH::_NoError)
6905 ret = -10000;
6906 else
6907 ret = ((int32_t)MsgStrings[ID].x) * 10000;
6908 break;
6909 }
6910 case MESSAGEDATAY: //SHORT
6911 {
6912 int32_t ID = ri->zmsgref;
6913
6914 if(BC::checkMessage(ID) != SH::_NoError)
6915 ret = -10000;
6916 else
6917 ret = ((int32_t)MsgStrings[ID].y) * 10000;
6918 break;
6919 }
6920 case MESSAGEDATAW: //UNSIGNED SHORT
6921 {
6922 int32_t ID = ri->zmsgref;
6923
6924 if(BC::checkMessage(ID) != SH::_NoError)
6925 ret = -10000;
6926 else
6927 ret = ((int32_t)MsgStrings[ID].w) * 10000;
6928 break;
6929 }
6930 case MESSAGEDATAH: //UNSIGNED SHORT
6931 {
6932 int32_t ID = ri->zmsgref;
6933
6934 if(BC::checkMessage(ID) != SH::_NoError)
6935 ret = -10000;
6936 else
6937 ret = ((int32_t)MsgStrings[ID].h) * 10000;
6938 break;
6939 }
6940 case MESSAGEDATASFX: //BYTE
6941 {
6942 int32_t ID = ri->zmsgref;
6943
6944 if(BC::checkMessage(ID) != SH::_NoError)
6945 ret = -10000;
6946 else
6947 ret = ((int32_t)MsgStrings[ID].sfx) * 10000;
6948 break;
6949 }
6950 case MESSAGEDATALISTPOS: //WORD
6951 {
6952 int32_t ID = ri->zmsgref;
6953
6954 if(BC::checkMessage(ID) != SH::_NoError)
6955 ret = -10000;
6956 else
6957 ret = ((int32_t)MsgStrings[ID].listpos) * 10000;
6958 break;
6959 }
6960 case MESSAGEDATAVSPACE: //BYTE
6961 {
6962 int32_t ID = ri->zmsgref;
6963
6964 if(BC::checkMessage(ID) != SH::_NoError)
6965 ret = -10000;
6966 else
6967 ret = ((int32_t)MsgStrings[ID].vspace) * 10000;
6968 break;
6969 }
6970 case MESSAGEDATAHSPACE: //BYTE
6971 {
6972 int32_t ID = ri->zmsgref;
6973
6974 if(BC::checkMessage(ID) != SH::_NoError)
6975 ret = -10000;
6976 else
6977 ret = ((int32_t)MsgStrings[ID].hspace) * 10000;
6978 break;
6979 }
6980 case MESSAGEDATAFLAGS: //BYTE
6981 {
6982 int32_t ID = ri->zmsgref;
6983
6984 if(BC::checkMessage(ID) != SH::_NoError)
6985 ret = -10000;
6986 else
6987 ret = ((int32_t)MsgStrings[ID].stringflags) * 10000;
6988 break;
6989 }
6990 case MESSAGEDATAPORTTILE: //INT
6991 {
6992 int32_t ID = ri->zmsgref;
6993
6994 if(BC::checkMessage(ID) != SH::_NoError)
6995 ret = -10000;
6996 else
6997 ret = ((int32_t)MsgStrings[ID].portrait_tile) * 10000;
6998 break;
6999 }
7000 case MESSAGEDATAPORTCSET: //BYTE
7001 {
7002 int32_t ID = ri->zmsgref;
7003
7004 if(BC::checkMessage(ID) != SH::_NoError)
7005 ret = -10000;
7006 else
7007 ret = ((int32_t)MsgStrings[ID].portrait_cset) * 10000;
7008 break;
7009 }
7010 case MESSAGEDATAPORTX: //BYTE
7011 {
7012 int32_t ID = ri->zmsgref;
7013
7014 if(BC::checkMessage(ID) != SH::_NoError)
7015 ret = -10000;
7016 else
7017 ret = ((int32_t)MsgStrings[ID].portrait_x) * 10000;
7018 break;
7019 }
7020 case MESSAGEDATAPORTY: //BYTE
7021 {
7022 int32_t ID = ri->zmsgref;
7023
7024 if(BC::checkMessage(ID) != SH::_NoError)
7025 ret = -10000;
7026 else
7027 ret = ((int32_t)MsgStrings[ID].portrait_y) * 10000;
7028 break;
7029 }
7030 case MESSAGEDATAPORTWID: //BYTE
7031 {
7032 int32_t ID = ri->zmsgref;
7033
7034 if(BC::checkMessage(ID) != SH::_NoError)
7035 ret = -10000;
7036 else
7037 ret = ((int32_t)MsgStrings[ID].portrait_tw) * 10000;
7038 break;
7039 }
7040 case MESSAGEDATAPORTHEI: //BYTE
7041 {
7042 int32_t ID = ri->zmsgref;
7043
7044 if(BC::checkMessage(ID) != SH::_NoError)
7045 ret = -10000;
7046 else
7047 ret = ((int32_t)MsgStrings[ID].portrait_th) * 10000;
7048 break;
7049 }
7050 case MESSAGEDATATEXTLEN: //BYTE
7051 {
7052 int32_t ID = ri->zmsgref;
7053
7054 if(BC::checkMessage(ID) != SH::_NoError)
7055 ret = -10000;
7056 else
7057 ret = int32_t(MsgStrings[ID].s.size()) * 10000;
7058 break;
7059 }
7060 case MESSAGEDATATEXTWID:
7061 {
7062 ret = do_msgwidth(ri->zmsgref)*10000;
7063 break;
7064 }
7065 case MESSAGEDATATEXTHEI:
7066 {
7067 ret = do_msgheight(ri->zmsgref)*10000;
7068 break;
7069 }
7070
7071 ///----------------------------------------------------------------------------------------------------//
7072 //combodata cd-> Getter variables
7073 #define GET_COMBO_VAR_INT(member) \
7074 { \
7075 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7076 { \
7077 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7078 ret = -10000; \
7079 } \
7080 else \
7081 { \
7082 ret = (combobuf[ri->combosref].member *10000); \
7083 } \
7084 } \
7085
7086 #define GET_COMBO_VAR_BYTE(member) \
7087 { \
7088 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7089 { \
7090 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7091 ret = -10000; \
7092 } \
7093 else \
7094 { \
7095 ret = (combobuf[ri->combosref].member *10000); \
7096 } \
7097 } \
7098
7099 #define GET_COMBO_VAR_DWORD(member) \
7100 { \
7101 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7102 { \
7103 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7104 ret = -10000; \
7105 } \
7106 else \
7107 { \
7108 ret = (combobuf[ri->combosref].member *10000); \
7109 } \
7110 } \
7111
7112 #define GET_COMBO_VAR_INDEX(member, indexbound) \
7113 { \
7114 int32_t indx = ri->d[rINDEX] / 10000; \
7115 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7116 { \
7117 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7118 ret = -10000; \
7119 } \
7120 else if ( indx < 0 || indx >= indexbound ) \
7121 { \
7122 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7123 ret = -10000; \
7124 } \
7125 else \
7126 { \
7127 ret = (combobuf[ri->combosref].member[indx] * 10000); \
7128 } \
7129 }
7130
7131 #define GET_COMBO_BYTE_INDEX(member, indexbound) \
7132 { \
7133 int32_t indx = ri->d[rINDEX] / 10000; \
7134 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7135 { \
7136 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7137 ret = -10000; \
7138 } \
7139 else if ( indx < 0 || indx >= indexbound ) \
7140 { \
7141 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7142 ret = -10000; \
7143 } \
7144 else \
7145 { \
7146 ret = (combobuf[ri->combosref].member[indx] * 100000); \
7147 } \
7148 }
7149
7150 #define GET_COMBO_FLAG(member, indexbound) \
7151 { \
7152 int32_t flag = (value/10000); \
7153 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7154 { \
7155 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7156 } \
7157 else \
7158 { \
7159 ret = (combobuf[ri->combosref].member&flag) ? 10000 : 0); \
7160 } \
7161 } \
7162
7163 //comboclass macros
7164
7165 #define GET_COMBOCLASS_VAR_INT(member) \
7166 { \
7167 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7168 { \
7169 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7170 ret = -10000; \
7171 } \
7172 else \
7173 { \
7174 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7175 } \
7176 } \
7177
7178 #define GET_COMBOCLASS_VAR_BYTE(member) \
7179 { \
7180 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7181 { \
7182 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7183 ret = -10000; \
7184 } \
7185 else \
7186 { \
7187 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7188 } \
7189 } \
7190
7191 #define GET_COMBOCLASS_VAR_DWORD(member) \
7192 { \
7193 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7194 { \
7195 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7196 ret = -10000; \
7197 } \
7198 else \
7199 { \
7200 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7201 } \
7202 } \
7203
7204 #define GET_COMBOCLASS_VAR_INDEX(member, indexbound) \
7205 { \
7206 int32_t indx = ri->d[rINDEX] / 10000; \
7207 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7208 { \
7209 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7210 ret = -10000; \
7211 } \
7212 else if ( indx < 0 || indx > indexbound ) \
7213 { \
7214 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7215 ret = -10000; \
7216 } \
7217 else \
7218 { \
7219 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 10000); \
7220 } \
7221 }
7222
7223 #define GET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
7224 { \
7225 int32_t indx = ri->d[rINDEX] / 10000; \
7226 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7227 { \
7228 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7229 ret = -10000; \
7230 } \
7231 else if ( indx < 0 || indx > indexbound ) \
7232 { \
7233 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7234 ret = -10000; \
7235 } \
7236 else \
7237 { \
7238 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 100000); \
7239 } \
7240 }
7241
7242 #define GET_COMBOCLASS_FLAG(member, indexbound) \
7243 { \
7244 int32_t flag = (value/10000); \
7245 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7246 { \
7247 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7248 } \
7249 else \
7250 { \
7251 ret = (combo_class_buf[combobuf[ri->combosref].type].member&flag) ? 10000 : 0); \
7252 } \
7253 } \
7254
7255 case COMBOXR:
7256 {
7257 //ri->combosref = id; //'this' pointer
7258 //ri->comboposref = i; //used for X(), Y(), Layer(), and so forth.
7259
1/2
✓ Branch 0 taken 60340 times.
✗ Branch 1 not taken.
60340 if ( curScriptType == ScriptType::Combo )
7260 {
7261 60340 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7262 60340 ret = (( COMBOX_REGION((rpos)) ) * 10000); //comboscriptstack[i]
7263 //this may be wrong...may need a special new var for this, storing the exact combopos
7264 //i is the current script number
7265 60340 }
7266 else
7267 {
7268 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname);
7269 ret = -10000;
7270 }
7271 60340 break;
7272 }
7273
7274 case COMBOYR:
7275 {
7276
1/2
✓ Branch 0 taken 12211 times.
✗ Branch 1 not taken.
12211 if ( curScriptType == ScriptType::Combo )
7277 {
7278 12211 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7279 12211 ret = (( COMBOY_REGION((rpos)) ) * 10000); //comboscriptstack[i]
7280 12211 }
7281 else
7282 {
7283 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7284 }
7285 12211 break;
7286 }
7287 case COMBOPOSR:
7288 {
7289
1/2
✓ Branch 0 taken 208371 times.
✗ Branch 1 not taken.
208371 if ( curScriptType == ScriptType::Combo )
7290 {
7291 208371 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7292 208371 ret = (int)rpos * 10000; //comboscriptstack[i]
7293 208371 }
7294 else
7295 {
7296 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7297 }
7298 208371 break;
7299 }
7300 case COMBOLAYERR:
7301 {
7302
1/2
✓ Branch 0 taken 19038 times.
✗ Branch 1 not taken.
19038 if ( curScriptType == ScriptType::Combo )
7303 {
7304 19038 int32_t layer = combopos_ref_to_layer(ri->comboposref);
7305 19038 ret = layer * 10000; //comboscriptstack[i]
7306 19038 }
7307 else
7308 {
7309 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7310 }
7311 19038 break;
7312 }
7313
7314 //NEWCOMBO STRUCT
7315
2/4
✓ Branch 0 taken 116988 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 116988 times.
116988 case COMBODTILE: GET_COMBO_VAR_DWORD(tile); break; //word
7316
2/4
✓ Branch 0 taken 112420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112420 times.
112420 case COMBODOTILE: GET_COMBO_VAR_DWORD(o_tile); break; //word
7317 case COMBODFRAME: GET_COMBO_VAR_BYTE(cur_frame); break; //char
7318 case COMBODACLK: GET_COMBO_VAR_BYTE(aclk); break; //char
7319 case COMBODASPEED: GET_COMBO_VAR_BYTE(speed); break; //char
7320
2/4
✓ Branch 0 taken 4546 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4546 times.
4546 case COMBODFLIP: GET_COMBO_VAR_BYTE(flip); break; //char
7321 case COMBODWALK:
7322 {
7323
2/4
✓ Branch 0 taken 6890 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6890 times.
6890 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7324 {
7325 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7326 ret = -10000;
7327 }
7328 else
7329 {
7330 6890 ret = ((combobuf[ri->combosref].walk&0x0F) *10000);
7331 }
7332 6890 break;
7333 }
7334 case COMBODEFFECT:
7335 {
7336
2/4
✓ Branch 0 taken 755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 755 times.
755 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7337 {
7338 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7339 ret = -10000;
7340 }
7341 else
7342 {
7343 755 ret = (((combobuf[ri->combosref].walk&0xF0)>>4) *10000);
7344 }
7345 755 break;
7346 }
7347
2/4
✓ Branch 0 taken 5110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5110 times.
5110 case COMBODTYPE: GET_COMBO_VAR_BYTE(type); break; //char
7348 case COMBODCSET:
7349 {
7350 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7351 {
7352 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7353 ret = -10000;
7354 }
7355 else
7356 {
7357 bool neg = combobuf[ri->combosref].csets&0x8;
7358 ret = ((combobuf[ri->combosref].csets&0x7) * (neg ? -10000 : 10000));
7359 }
7360 break;
7361 }
7362 case COMBODCSET2FLAGS:
7363 {
7364 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7365 {
7366 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7367 }
7368 else
7369 {
7370 ret = ((combobuf[ri->combosref].csets & 0xF0) >> 4) * 10000;
7371 }
7372 break;
7373 }
7374 case COMBODFOO: break; //W
7375
2/4
✓ Branch 0 taken 463074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 463074 times.
463074 case COMBODATASCRIPT: GET_COMBO_VAR_DWORD(script); break; //W
7376 case COMBODFRAMES: GET_COMBO_VAR_BYTE(frames); break; //C
7377 case COMBODNEXTD: GET_COMBO_VAR_INT(nextcombo); break; //W
7378 case COMBODNEXTC: GET_COMBO_VAR_BYTE(nextcset); break; //C
7379 case COMBODFLAG: GET_COMBO_VAR_BYTE(flag); break; //C
7380 case COMBODSKIPANIM: GET_COMBO_VAR_BYTE(skipanim); break; //C
7381 case COMBODNEXTTIMER: GET_COMBO_VAR_DWORD(nexttimer); break; //W
7382 case COMBODAKIMANIMY: GET_COMBO_VAR_BYTE(skipanimy); break; //C
7383 case COMBODANIMFLAGS: GET_COMBO_VAR_BYTE(animflags); break; //C
7384
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 case COMBODUSRFLAGS: GET_COMBO_VAR_INT(usrflags); break; //LONG
7385 case COMBODTRIGGERITEM:
7386 {
7387 ret = -10000;
7388 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7389 {
7390 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7391 }
7392 else if(auto* trig = get_first_combo_trigger())
7393 ret = trig->triggeritem * 10000;
7394 break;
7395 }
7396 case COMBODTRIGGERTIMER:
7397 {
7398 ret = -10000;
7399 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7400 {
7401 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7402 }
7403 else if(auto* trig = get_first_combo_trigger())
7404 ret = trig->trigtimer * 10000;
7405 break;
7406 }
7407 case COMBODTRIGGERSFX:
7408 {
7409 ret = -10000;
7410 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7411 {
7412 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7413 }
7414 else if(auto* trig = get_first_combo_trigger())
7415 ret = trig->trigsfx * 10000;
7416 break;
7417 }
7418 case COMBODTRIGGERCHANGECMB:
7419 {
7420 ret = -10000;
7421 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7422 {
7423 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7424 }
7425 else if(auto* trig = get_first_combo_trigger())
7426 ret = trig->trigchange * 10000;
7427 break;
7428 }
7429 case COMBODTRIGGERPROX:
7430 {
7431 ret = -10000;
7432 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7433 {
7434 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7435 }
7436 else if(auto* trig = get_first_combo_trigger())
7437 ret = trig->trigprox * 10000;
7438 break;
7439 }
7440 case COMBODTRIGGERLIGHTBEAM:
7441 {
7442 ret = -10000;
7443 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7444 {
7445 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7446 }
7447 else if(auto* trig = get_first_combo_trigger())
7448 ret = trig->triglbeam * 10000;
7449 break;
7450 }
7451 case COMBODTRIGGERCTR:
7452 {
7453 ret = -10000;
7454 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7455 {
7456 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7457 }
7458 else if(auto* trig = get_first_combo_trigger())
7459 ret = trig->trigctr * 10000;
7460 break;
7461 }
7462 case COMBODTRIGGERCTRAMNT:
7463 {
7464 ret = -10000;
7465 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7466 {
7467 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7468 }
7469 else if(auto* trig = get_first_combo_trigger())
7470 ret = trig->trigctramnt * 10000;
7471 break;
7472 }
7473 case COMBODTRIGGERCOOLDOWN:
7474 {
7475 ret = -10000;
7476 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7477 {
7478 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7479 }
7480 else if(auto* trig = get_first_combo_trigger())
7481 ret = trig->trigcooldown * 10000;
7482 break;
7483 }
7484 case COMBODTRIGGERCOPYCAT:
7485 {
7486 ret = -10000;
7487 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7488 {
7489 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7490 }
7491 else if(auto* trig = get_first_combo_trigger())
7492 ret = trig->trigcopycat * 10000;
7493 break;
7494 }
7495 case COMBODTRIGITEMPICKUP:
7496 {
7497 ret = -10000;
7498 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7499 {
7500 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7501 }
7502 else if(auto* trig = get_first_combo_trigger())
7503 ret = trig->spawnip * 10000;
7504 break;
7505 }
7506 case COMBODTRIGEXSTATE:
7507 {
7508 ret = -10000;
7509 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7510 {
7511 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7512 }
7513 else if(auto* trig = get_first_combo_trigger())
7514 ret = trig->exstate * 10000;
7515 break;
7516 }
7517 case COMBODTRIGEXDOORDIR:
7518 {
7519 ret = -10000;
7520 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7521 {
7522 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7523 }
7524 else if(auto* trig = get_first_combo_trigger())
7525 ret = trig->exdoor_dir * 10000;
7526 break;
7527 }
7528 case COMBODTRIGEXDOORIND:
7529 {
7530 ret = -10000;
7531 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7532 {
7533 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7534 }
7535 else if(auto* trig = get_first_combo_trigger())
7536 ret = trig->exdoor_ind * 10000;
7537 break;
7538 }
7539 case COMBODTRIGSPAWNENEMY:
7540 {
7541 ret = -10000;
7542 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7543 {
7544 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7545 }
7546 else if(auto* trig = get_first_combo_trigger())
7547 ret = trig->spawnenemy * 10000;
7548 break;
7549 }
7550 case COMBODTRIGSPAWNITEM:
7551 {
7552 25 ret = -10000;
7553
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
25 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7554 {
7555 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7556 }
7557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 else if(auto* trig = get_first_combo_trigger())
7558 25 ret = trig->spawnitem * 10000;
7559 25 break;
7560 }
7561 case COMBODTRIGCSETCHANGE:
7562 {
7563 ret = -10000;
7564 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7565 {
7566 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7567 }
7568 else if(auto* trig = get_first_combo_trigger())
7569 ret = trig->trigcschange * 10000;
7570 break;
7571 }
7572 case COMBODTRIGLITEMS:
7573 {
7574 ret = -10000;
7575 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7576 {
7577 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7578 }
7579 else if(auto* trig = get_first_combo_trigger())
7580 ret = trig->trig_levelitems * 10000;
7581 break;
7582 }
7583 case COMBODTRIGDMAPLVL:
7584 {
7585 ret = -10000;
7586 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7587 {
7588 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7589 }
7590 else if(auto* trig = get_first_combo_trigger())
7591 ret = trig->trigdmlevel * 10000;
7592 break;
7593 }
7594 case COMBODTRIGTINTR:
7595 {
7596 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7597 {
7598 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7599 break;
7600 }
7601 else if(auto* trig = get_first_combo_trigger())
7602 ret = trig->trigtint[0] * 10000;
7603 break;
7604 }
7605 case COMBODTRIGTINTG:
7606 {
7607 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7608 {
7609 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7610 }
7611 else if(auto* trig = get_first_combo_trigger())
7612 ret = trig->trigtint[1] * 10000;
7613 break;
7614 }
7615 case COMBODTRIGTINTB:
7616 {
7617 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7618 {
7619 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7620 }
7621 else if(auto* trig = get_first_combo_trigger())
7622 ret = trig->trigtint[2] * 10000;
7623 break;
7624 }
7625 case COMBODTRIGLVLPAL:
7626 {
7627 ret = -10000;
7628 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7629 {
7630 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7631 }
7632 else if(auto* trig = get_first_combo_trigger())
7633 ret = trig->triglvlpalette * 10000;
7634 break;
7635 }
7636 case COMBODTRIGBOSSPAL:
7637 {
7638 ret = -10000;
7639 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7640 {
7641 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7642 }
7643 else if(auto* trig = get_first_combo_trigger())
7644 ret = trig->trigbosspalette * 10000;
7645 break;
7646 }
7647 case COMBODTRIGQUAKETIME:
7648 {
7649 ret = -10000;
7650 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7651 {
7652 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7653 }
7654 else if(auto* trig = get_first_combo_trigger())
7655 ret = trig->trigquaketime * 10000;
7656 break;
7657 }
7658 case COMBODTRIGWAVYTIME:
7659 {
7660 ret = -10000;
7661 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7662 {
7663 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7664 }
7665 else if(auto* trig = get_first_combo_trigger())
7666 ret = trig->trigwavytime * 10000;
7667 break;
7668 }
7669 case COMBODTRIGSWORDJINX:
7670 {
7671 ret = -10000;
7672 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7673 {
7674 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7675 }
7676 else if(auto* trig = get_first_combo_trigger())
7677 ret = trig->trig_swjinxtime * 10000;
7678 break;
7679 }
7680 case COMBODTRIGITEMJINX:
7681 {
7682 ret = -10000;
7683 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7684 {
7685 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7686 }
7687 else if(auto* trig = get_first_combo_trigger())
7688 ret = trig->trig_itmjinxtime * 10000;
7689 break;
7690 }
7691 case COMBODTRIGSHIELDJINX:
7692 {
7693 ret = -10000;
7694 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
7695 {
7696 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7697 }
7698 else if(auto* trig = get_first_combo_trigger())
7699 ret = trig->trig_shieldjinxtime * 10000;
7700 break;
7701 }
7702 case COMBODTRIGSTUN:
7703 {
7704 ret = -10000;
7705 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7706 {
7707 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7708 }
7709 else if(auto* trig = get_first_combo_trigger())
7710 ret = trig->trig_stuntime * 10000;
7711 break;
7712 }
7713 case COMBODTRIGBUNNY:
7714 {
7715 ret = -10000;
7716 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7717 {
7718 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7719 }
7720 else if(auto* trig = get_first_combo_trigger())
7721 ret = trig->trig_bunnytime * 10000;
7722 break;
7723 }
7724 case COMBODTRIGPUSHTIME:
7725 {
7726 ret = -10000;
7727 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7728 {
7729 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7730 }
7731 else if(auto* trig = get_first_combo_trigger())
7732 ret = trig->trig_pushtime * 10000;
7733 break;
7734 }
7735 case COMBODLIFTGFXCOMBO:
7736 {
7737 ret = -10000;
7738 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7739 {
7740 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7741 }
7742 else ret = (combobuf[ri->combosref].liftcmb) * 10000;
7743 break;
7744 }
7745 case COMBODLIFTGFXCCSET:
7746 {
7747 ret = -10000;
7748 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7749 {
7750 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7751 }
7752 else ret = (combobuf[ri->combosref].liftcs) * 10000;
7753 break;
7754 }
7755 case COMBODLIFTUNDERCMB:
7756 {
7757 ret = -10000;
7758 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7759 {
7760 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7761 }
7762 else ret = (combobuf[ri->combosref].liftundercmb) * 10000;
7763 break;
7764 }
7765 case COMBODLIFTUNDERCS:
7766 {
7767 ret = -10000;
7768 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7769 {
7770 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7771 }
7772 else ret = (combobuf[ri->combosref].liftundercs) * 10000;
7773 break;
7774 }
7775 case COMBODLIFTDAMAGE:
7776 {
7777 ret = -10000;
7778 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7779 {
7780 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7781 }
7782 else ret = (combobuf[ri->combosref].liftdmg) * 10000;
7783 break;
7784 }
7785 case COMBODLIFTLEVEL:
7786 {
7787 ret = -10000;
7788 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7789 {
7790 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7791 }
7792 else ret = (combobuf[ri->combosref].liftlvl) * 10000;
7793 break;
7794 }
7795 case COMBODLIFTITEM:
7796 {
7797 ret = -10000;
7798 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7799 {
7800 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7801 }
7802 else ret = (combobuf[ri->combosref].liftitm) * 10000;
7803 break;
7804 }
7805 case COMBODLIFTGFXTYPE:
7806 {
7807 ret = -10000;
7808 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7809 {
7810 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7811 }
7812 else ret = (combobuf[ri->combosref].liftgfx) * 10000;
7813 break;
7814 }
7815 case COMBODLIFTGFXSPRITE:
7816 {
7817 ret = -10000;
7818 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7819 {
7820 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7821 }
7822 else ret = (combobuf[ri->combosref].liftsprite) * 10000;
7823 break;
7824 }
7825 case COMBODLIFTSFX:
7826 {
7827 ret = -10000;
7828 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7829 {
7830 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7831 }
7832 else ret = (combobuf[ri->combosref].liftsfx) * 10000;
7833 break;
7834 }
7835 case COMBODLIFTBREAKSPRITE:
7836 {
7837 ret = -10000;
7838 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7839 {
7840 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7841 }
7842 else ret = (combobuf[ri->combosref].liftbreaksprite) * 10000;
7843 break;
7844 }
7845 case COMBODLIFTBREAKSFX:
7846 {
7847 ret = -10000;
7848 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7849 {
7850 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7851 }
7852 else ret = (combobuf[ri->combosref].liftbreaksfx) * 10000;
7853 break;
7854 }
7855 case COMBODLIFTHEIGHT:
7856 {
7857 ret = -10000;
7858 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7859 {
7860 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7861 }
7862 else ret = (combobuf[ri->combosref].lifthei) * 10000;
7863 break;
7864 }
7865 case COMBODLIFTTIME:
7866 {
7867 ret = -10000;
7868 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7869 {
7870 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7871 }
7872 else ret = (combobuf[ri->combosref].lifttime) * 10000;
7873 break;
7874 }
7875 case COMBODLIFTLIGHTRAD:
7876 {
7877 ret = -10000;
7878 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7879 {
7880 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7881 }
7882 else ret = (combobuf[ri->combosref].lift_weap_data.light_rads[WPNSPR_BASE]) * 10000;
7883 break;
7884 }
7885 case COMBODLIFTLIGHTSHAPE:
7886 {
7887 ret = -10000;
7888 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7889 {
7890 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7891 }
7892 else ret = (combobuf[ri->combosref].lift_weap_data.glow_shape) * 10000;
7893 break;
7894 }
7895 case COMBODLIFTWEAPONITEM:
7896 {
7897 ret = -10000;
7898 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7899 {
7900 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7901 }
7902 else ret = (combobuf[ri->combosref].lift_parent_item) * 10000;
7903 break;
7904 }
7905 case COMBODTRIGGERLSTATE:
7906 {
7907 ret = -10000;
7908 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7909 {
7910 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7911 }
7912 else if(auto* trig = get_first_combo_trigger())
7913 ret = trig->trig_lstate * 10000;
7914 break;
7915 }
7916 case COMBODTRIGGERGSTATE:
7917 {
7918 ret = -10000;
7919 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7920 {
7921 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7922 }
7923 else if(auto* trig = get_first_combo_trigger())
7924 ret = trig->trig_gstate * 10000;
7925 break;
7926 }
7927 case COMBODTRIGGERGROUP:
7928 {
7929 ret = -10000;
7930 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7931 {
7932 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7933 }
7934 else if(auto* trig = get_first_combo_trigger())
7935 ret = trig->trig_group * 10000;
7936 break;
7937 }
7938 case COMBODTRIGGERGROUPVAL:
7939 {
7940 ret = -10000;
7941 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7942 {
7943 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7944 }
7945 else if(auto* trig = get_first_combo_trigger())
7946 ret = trig->trig_group_val * 10000;
7947 break;
7948 }
7949 case COMBODTRIGGERGTIMER:
7950 {
7951 ret = -10000;
7952 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7953 {
7954 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7955 }
7956 else if(auto* trig = get_first_combo_trigger())
7957 ret = trig->trig_statetime * 10000;
7958 break;
7959 }
7960 case COMBODTRIGGERGENSCRIPT:
7961 {
7962 ret = -10000;
7963 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7964 {
7965 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7966 }
7967 else if(auto* trig = get_first_combo_trigger())
7968 ret = trig->trig_genscr * 10000;
7969 break;
7970 }
7971
7972 case COMBODTRIGGERLEVEL:
7973 {
7974 ret = -10000;
7975 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7976 {
7977 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7978 }
7979 else if(auto* trig = get_first_combo_trigger())
7980 ret = trig->triggerlevel * 10000;
7981 break;
7982 }
7983 11602 case COMBODATAID: ret = (ri->combosref*10000); break;
7984 case COMBODNUMTRIGGERS:
7985 {
7986 ret = -10000;
7987 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7988 {
7989 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7990 }
7991 else ret = combobuf[ri->combosref].triggers.size() * 10000;
7992 break;
7993 }
7994 case COMBODONLYGEN:
7995 {
7996 ret = 0;
7997 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7998 {
7999 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
8000 }
8001 else ret = combobuf[ri->combosref].only_gentrig ? 10000 : 0;
8002 break;
8003 }
8004 case COMBOD_Z_HEIGHT:
8005 {
8006 ret = 0;
8007 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
8008 {
8009 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
8010 }
8011 else ret = combobuf[ri->combosref].z_height.getZLong();
8012 break;
8013 }
8014 case COMBOD_Z_STEP_HEIGHT:
8015 {
8016 ret = 0;
8017 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
8018 {
8019 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
8020 }
8021 else ret = combobuf[ri->combosref].z_step_height.getZLong();
8022 break;
8023 }
8024 //COMBOCLASS STRUCT
8025 //case COMBODNAME: //CHAR[64], STRING
8026 case COMBODBLOCKNPC: GET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
8027 case COMBODBLOCKHOLE: GET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
8028 case COMBODBLOCKTRIG: GET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
8029 case COMBODBLOCKWEAPON: GET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
8030 case COMBODCONVXSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
8031 case COMBODCONVYSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
8032 case COMBODSPAWNNPC: GET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
8033 case COMBODSPAWNNPCWHEN: GET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
8034 case COMBODSPAWNNPCCHANGE: GET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
8035 case COMBODDIRCHANGETYPE: GET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
8036 case COMBODDISTANCECHANGETILES: GET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
8037 case COMBODDIVEITEM: GET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
8038 case COMBODDOCK: GET_COMBOCLASS_VAR_BYTE(dock); break; //C
8039 case COMBODFAIRY: GET_COMBOCLASS_VAR_BYTE(fairy); break; //C
8040 case COMBODFFATTRCHANGE: GET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
8041 case COMBODFOORDECOTILE: GET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
8042 case COMBODFOORDECOTYPE: GET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
8043 case COMBODHOOKSHOTPOINT: GET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
8044 case COMBODLADDERPASS: GET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
8045 case COMBODLOCKBLOCK: GET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
8046 case COMBODLOCKBLOCKCHANGE: GET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
8047 case COMBODMAGICMIRROR: GET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
8048 case COMBODMODHPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
8049 case COMBODMODHPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
8050 case COMBODMODHPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
8051 case COMBODNMODMPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
8052 case COMBODMODMPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
8053 case COMBODMODMPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
8054 case COMBODNOPUSHBLOCK: GET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
8055 case COMBODOVERHEAD: GET_COMBOCLASS_VAR_BYTE(overhead); break; //C
8056 case COMBODPLACENPC: GET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
8057 case COMBODPUSHDIR: GET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
8058 case COMBODPUSHWAIT: GET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
8059 case COMBODPUSHHEAVY: GET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
8060 case COMBODPUSHED: GET_COMBOCLASS_VAR_BYTE(pushed); break; //C
8061 case COMBODRAFT: GET_COMBOCLASS_VAR_BYTE(raft); break; //C
8062 case COMBODRESETROOM: GET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
8063 case COMBODSAVEPOINTTYPE: GET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
8064 case COMBODSCREENFREEZETYPE: GET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
8065 case COMBODSECRETCOMBO: GET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
8066 case COMBODSINGULAR: GET_COMBOCLASS_VAR_BYTE(singular); break; //C
8067 case COMBODSLOWWALK: GET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
8068 case COMBODSTATUETYPE: GET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
8069 case COMBODSTEPTYPE: GET_COMBOCLASS_VAR_BYTE(step_type); break; //C
8070 case COMBODSTEPCHANGEINTO: GET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
8071 case COMBODSTRIKEWEAPONS: GET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
8072 case COMBODSTRIKEREMNANTS: GET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
8073 case COMBODSTRIKEREMNANTSTYPE: GET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
8074 case COMBODSTRIKECHANGE: GET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
8075 case COMBODSTRIKEITEM: GET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
8076 case COMBODTOUCHITEM: GET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
8077 case COMBODTOUCHSTAIRS: GET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
8078 case COMBODTRIGGERTYPE: GET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
8079 case COMBODTRIGGERSENS: GET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
8080 case COMBODWARPTYPE: GET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
8081 case COMBODWARPSENS: GET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
8082 case COMBODWARPDIRECT: GET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
8083 case COMBODWARPLOCATION: GET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
8084 case COMBODWATER: GET_COMBOCLASS_VAR_BYTE(water); break; //C
8085 case COMBODWHISTLE: GET_COMBOCLASS_VAR_BYTE(whistle); break; //C
8086 case COMBODWINGAME: GET_COMBOCLASS_VAR_BYTE(win_game); break; //C
8087 case COMBODBLOCKWPNLEVEL: GET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
8088
8089
8090
8091 ///----------------------------------------------------------------------------------------------------//
8092 case CMBTRIGWPNLEVEL:
8093 {
8094 if(auto* trig = get_combo_trigger(ri->combotrigref))
8095 {
8096 ret = trig->triggerlevel * 10000;
8097 }
8098 else ret = -10000;
8099 break;
8100 }
8101 case CMBTRIGREQITEM:
8102 {
8103 if(auto* trig = get_combo_trigger(ri->combotrigref))
8104 {
8105 ret = trig->triggeritem * 10000;
8106 }
8107 else ret = -10000;
8108 break;
8109 }
8110 case CMBTRIGTIMER:
8111 {
8112 if(auto* trig = get_combo_trigger(ri->combotrigref))
8113 {
8114 ret = trig->trigtimer * 10000;
8115 }
8116 else ret = -10000;
8117 break;
8118 }
8119 case CMBTRIGSFX:
8120 {
8121 if(auto* trig = get_combo_trigger(ri->combotrigref))
8122 {
8123 ret = trig->trigsfx * 10000;
8124 }
8125 else ret = -10000;
8126 break;
8127 }
8128 case CMBTRIGCHANGECMB:
8129 {
8130 if(auto* trig = get_combo_trigger(ri->combotrigref))
8131 {
8132 ret = trig->trigchange * 10000;
8133 }
8134 else ret = -10000;
8135 break;
8136 }
8137 case CMBTRIGCSETCHANGE:
8138 {
8139 if(auto* trig = get_combo_trigger(ri->combotrigref))
8140 {
8141 ret = trig->trigcschange * 10000;
8142 }
8143 else ret = -10000;
8144 break;
8145 }
8146 case CMBTRIGPROX:
8147 {
8148 if(auto* trig = get_combo_trigger(ri->combotrigref))
8149 {
8150 ret = trig->trigprox * 10000;
8151 }
8152 else ret = -10000;
8153 break;
8154 }
8155 case CMBTRIGLIGHTBEAM:
8156 {
8157 if(auto* trig = get_combo_trigger(ri->combotrigref))
8158 {
8159 ret = trig->triglbeam * 10000;
8160 }
8161 else ret = -10000;
8162 break;
8163 }
8164 case CMBTRIGCTR:
8165 {
8166 if(auto* trig = get_combo_trigger(ri->combotrigref))
8167 {
8168 ret = trig->trigctr * 10000;
8169 }
8170 else ret = -10000;
8171 break;
8172 }
8173 case CMBTRIGCTRAMNT:
8174 {
8175 if(auto* trig = get_combo_trigger(ri->combotrigref))
8176 {
8177 ret = trig->trigctramnt * 10000;
8178 }
8179 else ret = -10000;
8180 break;
8181 }
8182 case CMBTRIGCOOLDOWN:
8183 {
8184 if(auto* trig = get_combo_trigger(ri->combotrigref))
8185 {
8186 ret = trig->trigcooldown * 10000;
8187 }
8188 else ret = -10000;
8189 break;
8190 }
8191 case CMBTRIGCOPYCAT:
8192 {
8193 if(auto* trig = get_combo_trigger(ri->combotrigref))
8194 {
8195 ret = trig->trigcopycat * 10000;
8196 }
8197 else ret = -10000;
8198 break;
8199 }
8200 case CMBTRIGITEMPICKUP:
8201 {
8202 if(auto* trig = get_combo_trigger(ri->combotrigref))
8203 {
8204 ret = trig->spawnip * 10000;
8205 }
8206 else ret = -10000;
8207 break;
8208 }
8209 case CMBTRIGEXSTATE:
8210 {
8211 if(auto* trig = get_combo_trigger(ri->combotrigref))
8212 {
8213 ret = trig->exstate * 10000;
8214 }
8215 else ret = -10000;
8216 break;
8217 }
8218 case CMBTRIGEXDOORDIR:
8219 {
8220 if(auto* trig = get_combo_trigger(ri->combotrigref))
8221 {
8222 ret = trig->exdoor_dir * 10000;
8223 }
8224 else ret = -10000;
8225 break;
8226 }
8227 case CMBTRIGEXDOORIND:
8228 {
8229 if(auto* trig = get_combo_trigger(ri->combotrigref))
8230 {
8231 ret = trig->exdoor_ind * 10000;
8232 }
8233 else ret = -10000;
8234 break;
8235 }
8236 case CMBTRIGSPAWNENEMY:
8237 {
8238 if(auto* trig = get_combo_trigger(ri->combotrigref))
8239 {
8240 ret = trig->spawnenemy * 10000;
8241 }
8242 else ret = -10000;
8243 break;
8244 }
8245 case CMBTRIGSPAWNITEM:
8246 {
8247 if(auto* trig = get_combo_trigger(ri->combotrigref))
8248 {
8249 ret = trig->spawnitem * 10000;
8250 }
8251 else ret = -10000;
8252 break;
8253 }
8254 case CMBTRIGLSTATE:
8255 {
8256 if(auto* trig = get_combo_trigger(ri->combotrigref))
8257 {
8258 ret = trig->trig_lstate * 10000;
8259 }
8260 else ret = -10000;
8261 break;
8262 }
8263 case CMBTRIGGSTATE:
8264 {
8265 if(auto* trig = get_combo_trigger(ri->combotrigref))
8266 {
8267 ret = trig->trig_gstate * 10000;
8268 }
8269 else ret = -10000;
8270 break;
8271 }
8272 case CMBTRIGGTIMER:
8273 {
8274 if(auto* trig = get_combo_trigger(ri->combotrigref))
8275 {
8276 ret = trig->trig_statetime * 10000;
8277 }
8278 else ret = -10000;
8279 break;
8280 }
8281 case CMBTRIGGENSCRIPT:
8282 {
8283 if(auto* trig = get_combo_trigger(ri->combotrigref))
8284 {
8285 ret = trig->trig_genscr * 10000;
8286 }
8287 else ret = -10000;
8288 break;
8289 }
8290 case CMBTRIGGROUP:
8291 {
8292 if(auto* trig = get_combo_trigger(ri->combotrigref))
8293 {
8294 ret = trig->trig_group * 10000;
8295 }
8296 else ret = -10000;
8297 break;
8298 }
8299 case CMBTRIGGROUPVAL:
8300 {
8301 if(auto* trig = get_combo_trigger(ri->combotrigref))
8302 {
8303 ret = trig->trig_group_val * 10000;
8304 }
8305 else ret = -10000;
8306 break;
8307 }
8308 case CMBTRIGLITEMS:
8309 {
8310 if(auto* trig = get_combo_trigger(ri->combotrigref))
8311 {
8312 ret = trig->trig_levelitems * 10000;
8313 }
8314 else ret = -10000;
8315 break;
8316 }
8317 case CMBTRIGDMAPLVL:
8318 {
8319 if(auto* trig = get_combo_trigger(ri->combotrigref))
8320 {
8321 ret = trig->trigdmlevel * 10000;
8322 }
8323 else ret = -10000;
8324 break;
8325 }
8326 case CMBTRIGTINTR:
8327 {
8328 if(auto* trig = get_combo_trigger(ri->combotrigref))
8329 {
8330 ret = trig->trigtint[0] * 10000;
8331 }
8332 else ret = -10000;
8333 break;
8334 }
8335 case CMBTRIGTINTG:
8336 {
8337 if(auto* trig = get_combo_trigger(ri->combotrigref))
8338 {
8339 ret = trig->trigtint[1] * 10000;
8340 }
8341 else ret = -10000;
8342 break;
8343 }
8344 case CMBTRIGTINTB:
8345 {
8346 if(auto* trig = get_combo_trigger(ri->combotrigref))
8347 {
8348 ret = trig->trigtint[2] * 10000;
8349 }
8350 else ret = -10000;
8351 break;
8352 }
8353 case CMBTRIGLVLPAL:
8354 {
8355 if(auto* trig = get_combo_trigger(ri->combotrigref))
8356 {
8357 ret = trig->triglvlpalette * 10000;
8358 }
8359 else ret = -10000;
8360 break;
8361 }
8362 case CMBTRIGBOSSPAL:
8363 {
8364 if(auto* trig = get_combo_trigger(ri->combotrigref))
8365 {
8366 ret = trig->trigbosspalette * 10000;
8367 }
8368 else ret = -10000;
8369 break;
8370 }
8371 case CMBTRIGQUAKETIME:
8372 {
8373 if(auto* trig = get_combo_trigger(ri->combotrigref))
8374 {
8375 ret = trig->trigquaketime * 10000;
8376 }
8377 else ret = -10000;
8378 break;
8379 }
8380 case CMBTRIGWAVYTIME:
8381 {
8382 if(auto* trig = get_combo_trigger(ri->combotrigref))
8383 {
8384 ret = trig->trigwavytime * 10000;
8385 }
8386 else ret = -10000;
8387 break;
8388 }
8389 case CMBTRIGSWORDJINX:
8390 {
8391 if(auto* trig = get_combo_trigger(ri->combotrigref))
8392 {
8393 ret = trig->trig_swjinxtime * 10000;
8394 }
8395 else ret = -10000;
8396 break;
8397 }
8398 case CMBTRIGITEMJINX:
8399 {
8400 if(auto* trig = get_combo_trigger(ri->combotrigref))
8401 {
8402 ret = trig->trig_itmjinxtime * 10000;
8403 }
8404 else ret = -10000;
8405 break;
8406 }
8407 case CMBTRIGSHIELDJINX:
8408 {
8409 if(auto* trig = get_combo_trigger(ri->combotrigref))
8410 {
8411 ret = trig->trig_shieldjinxtime * 10000;
8412 }
8413 else ret = -10000;
8414 break;
8415 }
8416 case CMBTRIGSTUN:
8417 {
8418 if(auto* trig = get_combo_trigger(ri->combotrigref))
8419 {
8420 ret = trig->trig_stuntime * 10000;
8421 }
8422 else ret = -10000;
8423 break;
8424 }
8425 case CMBTRIGBUNNY:
8426 {
8427 if(auto* trig = get_combo_trigger(ri->combotrigref))
8428 {
8429 ret = trig->trig_bunnytime * 10000;
8430 }
8431 else ret = -10000;
8432 break;
8433 }
8434 case CMBTRIGPUSHTIME:
8435 {
8436 if(auto* trig = get_combo_trigger(ri->combotrigref))
8437 {
8438 ret = trig->trig_pushtime * 10000;
8439 }
8440 else ret = -10000;
8441 break;
8442 }
8443 case CMBTRIGGERPROMPTCID:
8444 {
8445 if(auto* trig = get_combo_trigger(ri->combotrigref))
8446 ret = trig->prompt_cid * 10000;
8447 else ret = -10000;
8448 break;
8449 }
8450 case CMBTRIGGERPROMPTCS:
8451 {
8452 if(auto* trig = get_combo_trigger(ri->combotrigref))
8453 ret = trig->prompt_cs * 10000;
8454 else ret = -10000;
8455 break;
8456 }
8457 case CMBTRIGGERFAILPROMPTCID:
8458 {
8459 if(auto* trig = get_combo_trigger(ri->combotrigref))
8460 ret = trig->fail_prompt_cid * 10000;
8461 else ret = -10000;
8462 break;
8463 }
8464 case CMBTRIGGERFAILPROMPTCS:
8465 {
8466 if(auto* trig = get_combo_trigger(ri->combotrigref))
8467 ret = trig->fail_prompt_cs * 10000;
8468 else ret = -10000;
8469 break;
8470 }
8471 case CMBTRIGGERPROMPTX:
8472 {
8473 if(auto* trig = get_combo_trigger(ri->combotrigref))
8474 ret = trig->prompt_x * 10000;
8475 else ret = -10000;
8476 break;
8477 }
8478 case CMBTRIGGERPROMPTY:
8479 {
8480 if(auto* trig = get_combo_trigger(ri->combotrigref))
8481 ret = trig->prompt_y * 10000;
8482 else ret = -10000;
8483 break;
8484 }
8485 case CMBTRIGGERTRIGSTR:
8486 {
8487 if(auto* trig = get_combo_trigger(ri->combotrigref))
8488 ret = trig->trig_msgstr * 10000;
8489 else ret = -10000;
8490 break;
8491 }
8492 case CMBTRIGGERFAILSTR:
8493 {
8494 if(auto* trig = get_combo_trigger(ri->combotrigref))
8495 ret = trig->fail_msgstr * 10000;
8496 else ret = -10000;
8497 break;
8498 }
8499 case CMBTRIGGERPLAYERBOUNCE:
8500 {
8501 if(auto* trig = get_combo_trigger(ri->combotrigref))
8502 ret = trig->player_bounce;
8503 else ret = -10000;
8504 break;
8505 }
8506 case CMBTRIGGERREQPLAYERZ:
8507 {
8508 if(auto* trig = get_combo_trigger(ri->combotrigref))
8509 ret = trig->req_player_z;
8510 else ret = -10000;
8511 break;
8512 }
8513 case CMBTRIGGERDESTHEROX:
8514 {
8515 if(auto* trig = get_combo_trigger(ri->combotrigref))
8516 ret = trig->dest_player_x;
8517 else ret = -10000;
8518 break;
8519 }
8520 case CMBTRIGGERDESTHEROY:
8521 {
8522 if(auto* trig = get_combo_trigger(ri->combotrigref))
8523 ret = trig->dest_player_y;
8524 else ret = -10000;
8525 break;
8526 }
8527 case CMBTRIGGERDESTHEROZ:
8528 {
8529 if(auto* trig = get_combo_trigger(ri->combotrigref))
8530 ret = trig->dest_player_z;
8531 else ret = -10000;
8532 break;
8533 }
8534 case CMBTRIGGERREQPLAYERJUMP:
8535 {
8536 if(auto* trig = get_combo_trigger(ri->combotrigref))
8537 ret = trig->req_player_jump;
8538 else ret = -10000;
8539 break;
8540 }
8541 case CMBTRIGGERREQPLAYERX:
8542 {
8543 if(auto* trig = get_combo_trigger(ri->combotrigref))
8544 ret = trig->req_player_x;
8545 else ret = -10000;
8546 break;
8547 }
8548 case CMBTRIGGERREQPLAYERY:
8549 {
8550 if(auto* trig = get_combo_trigger(ri->combotrigref))
8551 ret = trig->req_player_y;
8552 else ret = -10000;
8553 break;
8554 }
8555 case CMBTRIGGERFORCEPLAYERDIR:
8556 {
8557 if(auto* trig = get_combo_trigger(ri->combotrigref))
8558 ret = trig->dest_player_dir * 10000;
8559 else ret = -10000;
8560 break;
8561 }
8562 case CMBTRIGGERICECOMBO:
8563 {
8564 if(auto* trig = get_combo_trigger(ri->combotrigref))
8565 ret = trig->force_ice_combo * 10000;
8566 else ret = -10000;
8567 break;
8568 }
8569 case CMBTRIGGERICEVX:
8570 {
8571 if(auto* trig = get_combo_trigger(ri->combotrigref))
8572 ret = trig->force_ice_vx;
8573 else ret = -10000;
8574 break;
8575 }
8576 case CMBTRIGGERICEVY:
8577 {
8578 if(auto* trig = get_combo_trigger(ri->combotrigref))
8579 ret = trig->force_ice_vy;
8580 else ret = -10000;
8581 break;
8582 }
8583 ///----------------------------------------------------------------------------------------------------//
8584 //npcdata nd-> variables
8585
8586 //npcdata nd->member variable
8587 #define GET_NPCDATA_VAR_INT32(member, str) \
8588 { \
8589 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8590 { \
8591 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8592 ret = -10000; \
8593 } \
8594 else \
8595 { \
8596 ret = (guysbuf[ri->npcdataref].member *10000); \
8597 } \
8598 } \
8599
8600 #define GET_NPCDATA_VAR_BYTE(member, str) \
8601 { \
8602 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8603 { \
8604 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8605 ret = -10000; \
8606 } \
8607 else \
8608 { \
8609 ret = (guysbuf[ri->npcdataref].member *10000); \
8610 } \
8611 } \
8612
8613 #define GET_NPCDATA_VAR_INT16(member, str) \
8614 { \
8615 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8616 { \
8617 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8618 ret = -10000; \
8619 } \
8620 else \
8621 { \
8622 ret = (guysbuf[ri->npcdataref].member *10000); \
8623 } \
8624 } \
8625
8626 #define GET_NPCDATA_FLAG(member, str, indexbound) \
8627 { \
8628 int32_t flag = (value/10000); \
8629 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8630 { \
8631 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8632 } \
8633 else \
8634 { \
8635 ret = (guysbuf[ID].member&flag) ? 10000 : 0); \
8636 } \
8637 } \
8638
8639 // These are for compat only, though seemingly no quests even use these.
8640 case NPCDATAFLAGS1:
8641 {
8642 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
8643 {
8644 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags (deprecated)", (ri->npcdataref*10000));
8645 ret = -10000;
8646 }
8647 else
8648 {
8649 uint32_t value = guysbuf[ri->npcdataref].flags & 0xFFFFFFFFLL;
8650 ret = value * 10000;
8651 }
8652 }
8653 break;
8654 case NPCDATAFLAGS2:
8655 {
8656 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
8657 {
8658 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags2 (deprecated)", (ri->npcdataref*10000));
8659 ret = -10000;
8660 }
8661 else
8662 {
8663 uint32_t value = (guysbuf[ri->npcdataref].flags >> 32) & 0xFFFFFFFFLL;
8664 ret = value * 10000;
8665 }
8666 }
8667 break;
8668
8669 case NPCDATATILE: GET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
8670 case NPCDATAWIDTH: GET_NPCDATA_VAR_BYTE(width, "Width"); break;
8671 case NPCDATAHEIGHT: GET_NPCDATA_VAR_BYTE(height, "Height"); break;
8672 case NPCDATASTILE: GET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
8673 case NPCDATASWIDTH: GET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
8674 case NPCDATASHEIGHT: GET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
8675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATAETILE: GET_NPCDATA_VAR_INT32(e_tile, "ExTile"); break;
8676 case NPCDATAEWIDTH: GET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
8677 case NPCDATAEHEIGHT: GET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
8678 case NPCDATAHP: GET_NPCDATA_VAR_INT16(hp, "HP"); break;
8679 case NPCDATAFAMILY: GET_NPCDATA_VAR_INT16(family, "Family"); break;
8680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATACSET: GET_NPCDATA_VAR_INT16(cset, "CSet"); break;
8681 case NPCDATAANIM: GET_NPCDATA_VAR_INT16(anim, "Anim"); break;
8682 case NPCDATAEANIM: GET_NPCDATA_VAR_INT16(e_anim, "ExAnim"); break;
8683 case NPCDATAFRAMERATE: GET_NPCDATA_VAR_INT16(frate, "Framerate"); break;
8684 case NPCDATAEFRAMERATE: GET_NPCDATA_VAR_INT16(e_frate, "ExFramerate"); break;
8685 case NPCDATATOUCHDAMAGE: GET_NPCDATA_VAR_INT16(dp, "TouchDamage"); break;
8686 case NPCDATAWEAPONDAMAGE: GET_NPCDATA_VAR_INT16(wdp, "WeaponDamage"); break;
8687 case NPCDATAWEAPON: GET_NPCDATA_VAR_INT16(weapon, "Weapon"); break;
8688 case NPCDATARANDOM: GET_NPCDATA_VAR_INT16(rate, "Random"); break;
8689 case NPCDATAHALT: GET_NPCDATA_VAR_INT16(hrate, "Haltrate"); break;
8690 case NPCDATASTEP: GET_NPCDATA_VAR_INT16(step, "Step"); break;
8691 case NPCDATAHOMING: GET_NPCDATA_VAR_INT16(homing, "Homing"); break;
8692 case NPCDATAHUNGER: GET_NPCDATA_VAR_INT16(grumble, "Hunger"); break;
8693 case NPCDATADROPSET: GET_NPCDATA_VAR_INT16(item_set, "Dropset"); break;
8694 case NPCDATABGSFX: GET_NPCDATA_VAR_INT16(bgsfx, "BGSFX"); break;
8695 case NPCDATADEATHSFX: GET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
8696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 case NPCDATAHITSFX: GET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
8697 case NPCDATAXOFS: GET_NPCDATA_VAR_INT32(xofs, "DrawXOffset"); break;
8698 case NPCDATAYOFS: GET_NPCDATA_VAR_INT32(yofs, "DrawYOffset"); break;
8699 case NPCDATAZOFS: GET_NPCDATA_VAR_INT32(zofs, "DrawZOffset"); break;
8700 case NPCDATAHXOFS: GET_NPCDATA_VAR_INT32(hxofs, "HitXOffset"); break;
8701 case NPCDATAHYOFS: GET_NPCDATA_VAR_INT32(hyofs, "HitYOffset"); break;
8702 case NPCDATAHITWIDTH: GET_NPCDATA_VAR_INT32(hxsz, "HitWidth"); break;
8703 case NPCDATAHITHEIGHT: GET_NPCDATA_VAR_INT32(hysz, "HitHeight"); break;
8704 case NPCDATAHITZ: GET_NPCDATA_VAR_INT32(hzsz, "HitZHeight"); break;
8705 case NPCDATASCRIPT: GET_NPCDATA_VAR_INT32(script, "Script"); break;
8706 case NPCDATATILEWIDTH: GET_NPCDATA_VAR_INT32(txsz, "TileWidth"); break;
8707 case NPCDATATILEHEIGHT: GET_NPCDATA_VAR_INT32(tysz, "TileHeight"); break;
8708 case NPCDATAWPNSPRITE: GET_NPCDATA_VAR_INT32(wpnsprite, "WeaponSprite"); break;
8709 case NPCDATAWEAPONSCRIPT:
8710 {
8711 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
8712 {
8713 Z_scripterrlog("Invalid NPC ID passed to npcdata->WeaponScript: %d\n", (ri->npcdataref*10000));
8714 ret = -10000;
8715 }
8716 else ret = (guysbuf[ri->npcdataref].weap_data.script *10000);
8717 break;
8718 }
8719 case NPCDATASIZEFLAG: GET_NPCDATA_VAR_INT32(SIZEflags, "SizeFlags"); break;
8720
8721 case NPCDATAFROZENTILE: GET_NPCDATA_VAR_INT32(frozentile, "FrozenTile"); break;
8722 case NPCDATAFROZENCSET: GET_NPCDATA_VAR_INT32(frozencset, "FrozenCSet"); break;
8723 case NPCDATAFIRESFX: GET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
8724
8725 case NPCDSHADOWSPR:
8726 {
8727 if(ri->npcdataref > (MAXNPCS-1) )
8728 {
8729 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
8730 ret = -10000;
8731 }
8732 else
8733 {
8734 ret = guysbuf[ri->npcdataref].spr_shadow * 10000;
8735 }
8736 break;
8737 }
8738 case NPCDSPAWNSPR:
8739 {
8740 if(ri->npcdataref > (MAXNPCS-1) )
8741 {
8742 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
8743 ret = -10000;
8744 }
8745 else
8746 {
8747 ret = guysbuf[ri->npcdataref].spr_spawn * 10000;
8748 }
8749 break;
8750 }
8751 case NPCDDEATHSPR:
8752 {
8753 if(ri->npcdataref > (MAXNPCS-1) )
8754 {
8755 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
8756 ret = -10000;
8757 }
8758 else
8759 {
8760 ret = guysbuf[ri->npcdataref].spr_death * 10000;
8761 }
8762 break;
8763 }
8764
8765 case NPCMATCHINITDLABEL: //Same form as SetScreenD()
8766 //bool npcdata->MatchInitDLabel("label", d)
8767 {
8768
8769 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8770 {
8771 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "MatchInitDLabel()", (ri->npcdataref*10000));
8772 ret = 0;
8773 break;
8774 }
8775
8776 int32_t arrayptr = get_register(sarg1);
8777 int32_t init_d_index = get_register(sarg2) / 10000;
8778
8779 string name;
8780 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
8781
8782 bool match = (!( strcmp(name.c_str(), guysbuf[ri->npcdataref].initD_label[init_d_index] )));
8783
8784 ret = ( match ? 10000 : 0 );
8785 break;
8786 }
8787
8788 ///----------------------------------------------------------------------------------------------------//
8789 //Dropset Variables
8790
8791 case DROPSETNULLCHANCE:
8792 {
8793 if(ri->dropsetref > MAXITEMDROPSETS)
8794 {
8795 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
8796 ret = -10000;
8797 break;
8798 }
8799 ret = item_drop_sets[ri->dropsetref].chance[0] * 10000;
8800 break;
8801 }
8802 case DROPSETCHOOSE:
8803 {
8804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(ri->dropsetref > MAXITEMDROPSETS)
8805 {
8806 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
8807 ret = -10000;
8808 break;
8809 }
8810 10 ret = select_dropitem(ri->dropsetref) * 10000;
8811 10 break;
8812 }
8813
8814 ///----------------------------------------------------------------------------------------------------//
8815 //Audio Variables
8816
8817 case AUDIOPAN:
8818 {
8819 ret = FFScript::do_getSFX_pan() * 10000;
8820 break;
8821 }
8822
8823 ///----------------------------------------------------------------------------------------------------//
8824 //Graphics->
8825
8826 case NUMDRAWS:
8827 ret = script_drawing_commands.Count() * 10000;
8828 //ret = FFCore.numscriptdraws * 10000; // This isn't updated until end of frame, making it useless!
8829 break;
8830
8831 case MAXDRAWS:
8832 ret = MAX_SCRIPT_DRAWING_COMMANDS * 10000;
8833 break;
8834
8835 case BITMAPWIDTH:
8836 {
8837
2/4
✓ Branch 0 taken 3453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3453 times.
✗ Branch 3 not taken.
3453 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
8838 {
8839 3453 ret = bmp->width * 10000;
8840 3453 }
8841 else
8842 {
8843 ret = -10000;
8844 }
8845 3453 break;
8846 }
8847
8848 case BITMAPHEIGHT:
8849 {
8850 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
8851 {
8852 ret = bmp->height * 10000;
8853 }
8854 else
8855 {
8856 ret = -10000;
8857 }
8858 break;
8859 }
8860 ///----------------------------------------------------------------------------------------------------//
8861 //File->
8862 case FILEPOS:
8863 {
8864 if(user_file* f = checkFile(ri->fileref, true))
8865 {
8866 ret = ftell(f->file); //NOT *10000 -V
8867 }
8868 else ret = -10000L;
8869 break;
8870 }
8871 case FILEEOF:
8872 {
8873 if(user_file* f = checkFile(ri->fileref, true))
8874 {
8875 ret = feof(f->file) ? 10000L : 0L; //Boolean
8876 }
8877 else ret = -10000L;
8878 break;
8879 }
8880 case FILEERR:
8881 {
8882 if(user_file* f = checkFile(ri->fileref, true))
8883 {
8884 ret = ferror(f->file) * 10000L;
8885 }
8886 else ret = -10000L;
8887 break;
8888 }
8889
8890 ///----------------------------------------------------------------------------------------------------//
8891 //Directory->
8892 case DIRECTORYSIZE:
8893 {
8894 if(user_dir* dr = checkDir(ri->directoryref, true))
8895 {
8896 ret = dr->size() * 10000L;
8897 }
8898 else ret = -10000L;
8899 break;
8900 }
8901
8902 ///----------------------------------------------------------------------------------------------------//
8903 //Stack->
8904 case STACKSIZE:
8905 {
8906 if(user_stack* st = checkStack(ri->stackref, true))
8907 {
8908 ret = st->size(); //NOT *10000
8909 }
8910 else ret = -10000L;
8911 break;
8912 }
8913 case STACKFULL:
8914 {
8915 if(user_stack* st = checkStack(ri->stackref, true))
8916 {
8917 ret = st->full() ? 10000L : 0L;
8918 }
8919 else ret = -10000L;
8920 break;
8921 }
8922
8923 ///----------------------------------------------------------------------------------------------------//
8924 //Misc./Internal
8925 case REFFFC:
8926
2/2
✓ Branch 0 taken 738 times.
✓ Branch 1 taken 25916 times.
26654 ret = ZScriptVersion::ffcRefIsSpriteId() ? ri->ffcref : ri->ffcref * 10000;
8927 26654 break;
8928
8929 case REFITEM:
8930 608463 ret = ri->itemref;
8931 608463 break;
8932
8933 case REFITEMCLASS:
8934 5613429 ret = ri->idata;
8935 5613429 break;
8936
8937 case REFLWPN:
8938 1561195 ret = ri->lwpn;
8939 1561195 break;
8940
8941 case REFEWPN:
8942 4923551 ret = ri->ewpn;
8943 4923551 break;
8944
8945 case REFNPC:
8946 27873688 ret = ri->guyref;
8947 27873688 break;
8948
8949 case REFSPRITE:
8950 ret = ri->spriteref;
8951 break;
8952
8953 case REFMAPDATA: ret = ri->mapsref; break;
8954 20 case REFSCREENDATA: ret = ri->screenref; break;
8955 215684 case REFCOMBODATA: ret = ri->combosref; break;
8956 case REFCOMBOTRIGGER: ret = ri->combotrigref; break;
8957 16 case REFSPRITEDATA: ret = ri->spritedataref; break;
8958 10 case REFBITMAP: ret = ri->bitmapref; break;
8959 1 case REFNPCCLASS: ret = ri->npcdataref; break;
8960
8961
8962 72930 case REFDMAPDATA: ret = ri->dmapsref; break;
8963 case REFSHOPDATA: ret = ri->shopsref; break;
8964 24 case REFMSGDATA: ret = ri->zmsgref; break;
8965
8966 10 case REFDROPS: ret = ri->dropsetref; break;
8967 case REFBOTTLETYPE: ret = ri->bottletyperef; break;
8968 case REFBOTTLESHOP: ret = ri->bottleshopref; break;
8969 137715 case REFGENERICDATA: ret = ri->genericdataref; break;
8970 case REFFILE: ret = ri->fileref; break;
8971 case REFDIRECTORY: ret = ri->directoryref; break;
8972 case REFSTACK: ret = ri->stackref; break;
8973 36 case REFSUBSCREEN: ret = ri->subdataref; break;
8974 case REFSUBSCREENPAGE: ret = ri->subpageref; break;
8975 case REFSUBSCREENWIDG: ret = ri->subwidgref; break;
8976 case REFRNG: ret = ri->rngref; break;
8977 case REFWEBSOCKET: ret = ri->websocketref; break;
8978 6314 case CLASS_THISKEY: ret = ri->thiskey; break;
8979 1119 case CLASS_THISKEY2: ret = ri->thiskey2; break;
8980 case REFPALDATA: ret = ri->paldataref; break;
8981
8982
8983 case SP:
8984 8 ret = ri->sp * 10000;
8985 8 break;
8986 case SP2:
8987 70504508 ret = ri->sp;
8988 70504508 break;
8989
8990 case PC:
8991 ret = ri->pc;
8992 break;
8993
8994 case SWITCHKEY:
8995 1573532 ret = ri->switchkey;
8996 1573532 break;
8997
8998 case SCRIPTRAM:
8999 case GLOBALRAM:
9000 1125663338 ret = ArrayH::getElement(ri->d[rINDEX], ri->d[rINDEX2] / 10000);
9001 1125663338 break;
9002
9003 case SCRIPTRAMD:
9004 case GLOBALRAMD:
9005 ret = ArrayH::getElement(ri->d[rINDEX], 0);
9006 break;
9007
9008 case GDD: // Unused, remove?
9009 ret = read_array(game->global_d, ri->d[rINDEX] / 10000);
9010 break;
9011
9012 ///----------------------------------------------------------------------------------------------------//
9013
9014 case GENDATARUNNING:
9015 {
9016 5519 ret = 0;
9017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5519 times.
5519 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
9018 {
9019 5519 ret = scr->doscript() ? 10000L : 0L;
9020 5519 }
9021 5519 break;
9022 }
9023 case GENDATASIZE:
9024 {
9025 ret = 0;
9026 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
9027 {
9028 ret = scr->dataSize()*10000;
9029 }
9030 break;
9031 }
9032
9033 ///----------------------------------------------------------------------------------------------------//
9034
9035 case PORTALX:
9036 {
9037 ret = -10000;
9038 if(portal* p = checkPortal(ri->portalref))
9039 ret = p->x.getZLong();
9040 break;
9041 }
9042 case PORTALY:
9043 {
9044 ret = -10000;
9045 if(portal* p = checkPortal(ri->portalref))
9046 ret = p->y.getZLong();
9047 break;
9048 }
9049 case PORTALDMAP:
9050 {
9051 ret = -10000;
9052 if(portal* p = checkPortal(ri->portalref))
9053 ret = p->destdmap*10000;
9054 break;
9055 }
9056 case PORTALSCREEN:
9057 {
9058 ret = -10000;
9059 if(portal* p = checkPortal(ri->portalref))
9060 ret = p->destscr*10000;
9061 break;
9062 }
9063 case PORTALACLK:
9064 {
9065 ret = -10000;
9066 if(portal* p = checkPortal(ri->portalref))
9067 ret = p->aclk*10000;
9068 break;
9069 }
9070 case PORTALAFRM:
9071 {
9072 ret = -10000;
9073 if(portal* p = checkPortal(ri->portalref))
9074 ret = p->aframe*10000;
9075 break;
9076 }
9077 case PORTALOTILE:
9078 {
9079 ret = -10000;
9080 if(portal* p = checkPortal(ri->portalref))
9081 ret = p->o_tile*10000;
9082 break;
9083 }
9084 case PORTALASPD:
9085 {
9086 ret = -10000;
9087 if(portal* p = checkPortal(ri->portalref))
9088 ret = p->aspd*10000;
9089 break;
9090 }
9091 case PORTALFRAMES:
9092 {
9093 ret = -10000;
9094 if(portal* p = checkPortal(ri->portalref))
9095 ret = p->frames*10000;
9096 break;
9097 }
9098 case PORTALSAVED:
9099 {
9100 ret = 0;
9101 if(portal* p = checkPortal(ri->portalref))
9102 ret = p->saved_data;
9103 break;
9104 }
9105 case PORTALCLOSEDIS:
9106 {
9107 ret = 0;
9108 if(portal* p = checkPortal(ri->portalref))
9109 ret = p->prox_active ? 0 : 10000; //Inverted
9110 break;
9111 }
9112 case REFPORTAL:
9113 {
9114 ret = ri->portalref;
9115 break;
9116 }
9117 case REFSAVPORTAL:
9118 {
9119 ret = ri->saveportalref;
9120 break;
9121 }
9122 case PORTALWARPSFX:
9123 {
9124 ret = 0;
9125 if(portal* p = checkPortal(ri->portalref))
9126 ret = p->wsfx ? 0 : 10000;
9127 break;
9128 }
9129 case PORTALWARPVFX:
9130 {
9131 ret = 0;
9132 if(portal* p = checkPortal(ri->portalref))
9133 ret = p->weffect ? 0 : 10000;
9134 break;
9135 }
9136 case SAVEDPORTALX:
9137 {
9138 ret = -10000;
9139 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9140 ret = p->x;
9141 break;
9142 }
9143 case SAVEDPORTALY:
9144 {
9145 ret = -10000;
9146 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9147 ret = p->y;
9148 break;
9149 }
9150 case SAVEDPORTALSRCDMAP:
9151 {
9152 ret = -10000;
9153 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9154 ret = p->srcdmap * 10000;
9155 break;
9156 }
9157 case SAVEDPORTALDESTDMAP:
9158 {
9159 ret = -10000;
9160 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9161 ret = p->destdmap * 10000;
9162 break;
9163 }
9164 case SAVEDPORTALSRCSCREEN:
9165 {
9166 ret = -10000;
9167 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9168 ret = p->srcscr * 10000;
9169 break;
9170 }
9171 case SAVEDPORTALDSTSCREEN:
9172 {
9173 ret = -10000;
9174 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9175 ret = p->destscr * 10000;
9176 break;
9177 }
9178 case SAVEDPORTALWARPSFX:
9179 {
9180 ret = -10000;
9181 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9182 ret = p->sfx * 10000;
9183 break;
9184 }
9185 case SAVEDPORTALWARPVFX:
9186 {
9187 ret = -10000;
9188 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9189 ret = p->warpfx * 10000;
9190 break;
9191 }
9192 case SAVEDPORTALSPRITE:
9193 {
9194 ret = -10000;
9195 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9196 ret = p->spr * 10000;
9197 break;
9198 }
9199 case SAVEDPORTALPORTAL:
9200 {
9201 ret = 0;
9202 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9203 ret = getPortalFromSaved(p);
9204 break;
9205 }
9206 case PORTALCOUNT:
9207 {
9208 ret = portals.Count()*10000;
9209 break;
9210 }
9211 case SAVEDPORTALCOUNT:
9212 {
9213 ret = game->user_portals.size()*10000;
9214 break;
9215 }
9216
9217 case GAMEASUBOPEN:
9218 {
9219 ret = subscreen_open ? 10000 : 0;
9220 break;
9221 }
9222 case GAMEASUBYOFF:
9223 {
9224 14124 ret = active_sub_yoff*10000;
9225 14124 break;
9226 }
9227 case GAMENUMASUB:
9228 {
9229 ret = subscreens_active.size()*10000;
9230 break;
9231 }
9232 case GAMENUMPSUB:
9233 {
9234 ret = subscreens_passive.size()*10000;
9235 break;
9236 }
9237 case GAMENUMOSUB:
9238 {
9239 ret = subscreens_overlay.size()*10000;
9240 break;
9241 }
9242
9243 ///----------------------------------------------------------------------------------------------------//
9244
9245 case SUBDATACURPG:
9246 {
9247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
54674 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
109348 if(sub->sub_type == sstACTIVE)
9249 54674 ret = 10000*sub->curpage;
9250 54674 break;
9251 }
9252 case SUBDATANUMPG:
9253 {
9254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9255 {
9256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub->sub_type == sstACTIVE)
9257 11 ret = 10000*sub->pages.size();
9258 else ret = 10000;
9259 11 }
9260 11 break;
9261 }
9262 case SUBDATATYPE:
9263 {
9264 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9265 ret = sub->sub_type*10000;
9266 break;
9267 }
9268
9269 ///---- ACTIVE SUBSCREENS ONLY
9270 case SUBDATACURSORPOS:
9271 {
9272 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9273 {
9274 SubscrPage& pg = sub->cur_page();
9275 ret = pg.cursor_pos * 10000;
9276 }
9277 break;
9278 }
9279 case SUBDATASCRIPT:
9280 {
9281 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9282 ret = sub->script * 10000;
9283 break;
9284 }
9285 case SUBDATATRANSLEFTTY:
9286 {
9287 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9288 {
9289 auto& trans = sub->trans_left;
9290 ret = trans.type * 10000;
9291 }
9292 break;
9293 }
9294 case SUBDATATRANSLEFTSFX:
9295 {
9296 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9297 {
9298 auto& trans = sub->trans_left;
9299 ret = trans.tr_sfx * 10000;
9300 }
9301 break;
9302 }
9303 case SUBDATATRANSRIGHTTY:
9304 {
9305 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9306 {
9307 auto& trans = sub->trans_right;
9308 ret = trans.type * 10000;
9309 }
9310 break;
9311 }
9312 case SUBDATATRANSRIGHTSFX:
9313 {
9314 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9315 {
9316 auto& trans = sub->trans_right;
9317 ret = trans.tr_sfx * 10000;
9318 }
9319 break;
9320 }
9321 case SUBDATASELECTORDSTX:
9322 {
9323 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9324 ret = sub->selector_setting.x * 10000;
9325 break;
9326 }
9327 case SUBDATASELECTORDSTY:
9328 {
9329 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9330 ret = sub->selector_setting.y * 10000;
9331 break;
9332 }
9333 case SUBDATASELECTORDSTW:
9334 {
9335 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9336 ret = sub->selector_setting.w * 10000;
9337 break;
9338 }
9339 case SUBDATASELECTORDSTH:
9340 {
9341 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9342 ret = sub->selector_setting.h * 10000;
9343 break;
9344 }
9345 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
9346 case SUBDATATRANSCLK:
9347 {
9348 5031 ret = -10000;
9349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9350 {
9351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(sub != new_subscreen_active)
9352 Z_scripterrlog("'subscreendata->TransClock' is only"
9353 " valid for the current active subscreen!\n");
9354
3/4
✓ Branch 0 taken 5031 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4855 times.
✓ Branch 3 taken 176 times.
5031 else if(subscreen_open && subscr_pg_animating)
9355 176 ret = subscr_pg_clk*10000;
9356 5031 }
9357 5031 break;
9358 }
9359 case SUBDATATRANSTY:
9360 {
9361 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9362 {
9363 auto& trans = subscr_pg_transition;
9364 if(sub != new_subscreen_active)
9365 Z_scripterrlog("'subscreendata->TransType' is only"
9366 " valid for the current active subscreen!\n");
9367 else if(subscreen_open)
9368 ret = trans.type*10000;
9369 }
9370 break;
9371 }
9372 case SUBDATATRANSFROMPG:
9373 {
9374 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9375 {
9376 if(sub != new_subscreen_active)
9377 Z_scripterrlog("'subscreendata->TransFromPage' is only"
9378 " valid for the current active subscreen!\n");
9379 else if(subscreen_open)
9380 ret = subscr_pg_from*10000;
9381 }
9382 break;
9383 }
9384 case SUBDATATRANSTOPG:
9385 {
9386 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9387 {
9388 if(sub != new_subscreen_active)
9389 Z_scripterrlog("'subscreendata->TransToPage' is only"
9390 " valid for the current active subscreen!\n");
9391 else if(subscreen_open)
9392 ret = subscr_pg_to*10000;
9393 }
9394 break;
9395 }
9396
9397 ///----------------------------------------------------------------------------------------------------//
9398 case SUBPGINDEX:
9399 {
9400 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9401 ret = pg->getIndex() * 10000;
9402 break;
9403 }
9404 case SUBPGNUMWIDG:
9405 {
9406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1005 times.
1005 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9407 1005 ret = pg->size() * 10000;
9408 1005 break;
9409 }
9410 case SUBPGSUBDATA:
9411 {
9412 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9413 {
9414 auto [sub,ty,_pgid,_ind] = from_subref(ri->subpageref);
9415 ret = get_subref(sub,ty,0,0);
9416 }
9417 break;
9418 }
9419 case SUBPGCURSORPOS:
9420 {
9421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17326 times.
17326 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9422 17326 ret = pg->cursor_pos * 10000;
9423 17326 break;
9424 }
9425 ///----------------------------------------------------------------------------------------------------//
9426 ///---- ANY WIDGET TYPE
9427 case SUBWIDGTYPE:
9428 {
9429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6024 times.
6024 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9430 6024 ret = 10000*widg->getType();
9431 6024 break;
9432 }
9433 case SUBWIDGINDEX:
9434 {
9435 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9436 {
9437 auto [_sub,_ty,_pgid,ind] = from_subref(ri->subwidgref);
9438 ret = 10000*ind;
9439 }
9440 break;
9441 }
9442 case SUBWIDGDISPITM:
9443 {
9444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4206 times.
4206 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9445 {
9446 4206 ret = 10000*widg->getDisplayItem();
9447 4206 }
9448 4206 break;
9449 }
9450 case SUBWIDGEQPITM:
9451 {
9452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9836 times.
9836 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9453 {
9454 9836 ret = 10000*widg->getItemVal();
9455 9836 }
9456 9836 break;
9457 }
9458 case SUBWIDGPAGE:
9459 {
9460 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9461 {
9462 auto [sub,ty,pgid,_ind] = from_subref(ri->subwidgref);
9463 ret = get_subref(sub,ty,pgid,0);
9464 }
9465 break;
9466 }
9467 case SUBWIDGPOS:
9468 {
9469 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9470 ret = 10000*widg->pos;
9471 break;
9472 }
9473 case SUBWIDGX:
9474 {
9475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9476 339 ret = 10000*widg->x;
9477 339 break;
9478 }
9479 case SUBWIDGY:
9480 {
9481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9482 339 ret = 10000*widg->y;
9483 339 break;
9484 }
9485 case SUBWIDGW:
9486 {
9487 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9488 ret = 10000*widg->w;
9489 break;
9490 }
9491 case SUBWIDGH:
9492 {
9493 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9494 ret = 10000*widg->h;
9495 break;
9496 }
9497 case SUBWIDG_DISPX:
9498 {
9499 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9500 ret = 10000*widg->getX();
9501 break;
9502 }
9503 case SUBWIDG_DISPY:
9504 {
9505 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9506 ret = 10000*widg->getY();
9507 break;
9508 }
9509 case SUBWIDG_DISPW:
9510 {
9511 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9512 ret = 10000*widg->getW();
9513 break;
9514 }
9515 case SUBWIDG_DISPH:
9516 {
9517 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9518 ret = 10000*widg->getH();
9519 break;
9520 }
9521 case SUBWIDGREQCOUNTER:
9522 {
9523 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9524 ret = 10000 * widg->req_counter;
9525 break;
9526 }
9527 case SUBWIDGREQCOUNTERCOND:
9528 {
9529 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9530 ret = 10000 * widg->req_counter_cond_type;
9531 break;
9532 }
9533 case SUBWIDGREQCOUNTERVAL:
9534 {
9535 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9536 ret = 10000 * widg->req_counter_val;
9537 break;
9538 }
9539 case SUBWIDGREQLITEMS:
9540 {
9541 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9542 ret = 10000 * widg->req_litems;
9543 break;
9544 }
9545 case SUBWIDGREQLITEMLEVEL:
9546 {
9547 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9548 ret = 10000 * widg->req_litem_level;
9549 break;
9550 }
9551 case SUBWIDGREQSCRIPTDISABLED:
9552 {
9553 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9554 ret = widg->is_disabled ? 10000 : 0;
9555 break;
9556 }
9557 ///---- ACTIVE SUBSCREENS ONLY
9558 case SUBWIDGSELECTORDSTX:
9559 {
9560 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9561 ret = 10000*widg->selector_override.x;
9562 break;
9563 }
9564 case SUBWIDGSELECTORDSTY:
9565 {
9566 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9567 ret = 10000*widg->selector_override.y;
9568 break;
9569 }
9570 case SUBWIDGSELECTORDSTW:
9571 {
9572 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9573 ret = 10000*widg->selector_override.w;
9574 break;
9575 }
9576 case SUBWIDGSELECTORDSTH:
9577 {
9578 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9579 ret = 10000*widg->selector_override.h;
9580 break;
9581 }
9582
9583 case SUBWIDGPRESSSCRIPT:
9584 {
9585 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9586 ret = 10000*widg->generic_script;
9587 break;
9588 }
9589 case SUBWIDGPGMODE:
9590 {
9591 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9592 ret = 10000*widg->pg_mode;
9593 break;
9594 }
9595 case SUBWIDGPGTARG:
9596 {
9597 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9598 ret = 10000*widg->pg_targ;
9599 break;
9600 }
9601
9602 case SUBWIDGTRANSPGTY:
9603 {
9604 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9605 {
9606 auto& trans = widg->pg_trans;
9607 ret = 10000*trans.type;
9608 }
9609 break;
9610 }
9611 case SUBWIDGTRANSPGSFX:
9612 {
9613 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9614 {
9615 auto& trans = widg->pg_trans;
9616 ret = 10000*trans.tr_sfx;
9617 }
9618 break;
9619 }
9620 ///---- VARYING WIDGET TYPES
9621 case SUBWIDGTY_FONT:
9622 {
9623 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9624 {
9625 auto ty = widg->getType();
9626 switch(ty)
9627 {
9628 case widgTEXT:
9629 ret = 10000*((SW_Text*)widg)->fontid;
9630 break;
9631 case widgTEXTBOX:
9632 ret = 10000*((SW_TextBox*)widg)->fontid;
9633 break;
9634 case widgSELECTEDTEXT:
9635 ret = 10000*((SW_SelectedText*)widg)->fontid;
9636 break;
9637 case widgTIME:
9638 ret = 10000*((SW_Time*)widg)->fontid;
9639 break;
9640 case widgCOUNTER:
9641 ret = 10000*((SW_Counter*)widg)->fontid;
9642 break;
9643 case widgBTNCOUNTER:
9644 ret = 10000*((SW_BtnCounter*)widg)->fontid;
9645 break;
9646 case widgOLDCTR:
9647 ret = 10000*((SW_Counters*)widg)->fontid;
9648 break;
9649 case widgMMAPTITLE:
9650 ret = 10000*((SW_MMapTitle*)widg)->fontid;
9651 break;
9652 default:
9653 bad_subwidg_type(false, ty);
9654 ret = -10000;
9655 break;
9656 }
9657 }
9658 break;
9659 }
9660 case SUBWIDGTY_ALIGN:
9661 {
9662 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9663 {
9664 auto ty = widg->getType();
9665 switch(ty)
9666 {
9667 case widgTEXT:
9668 ret = 10000*((SW_Text*)widg)->align;
9669 break;
9670 case widgTEXTBOX:
9671 ret = 10000*((SW_TextBox*)widg)->align;
9672 break;
9673 case widgSELECTEDTEXT:
9674 ret = 10000*((SW_SelectedText*)widg)->align;
9675 break;
9676 case widgTIME:
9677 ret = 10000*((SW_Time*)widg)->align;
9678 break;
9679 case widgCOUNTER:
9680 ret = 10000*((SW_Counter*)widg)->align;
9681 break;
9682 case widgBTNCOUNTER:
9683 ret = 10000*((SW_BtnCounter*)widg)->align;
9684 break;
9685 case widgMMAPTITLE:
9686 ret = 10000*((SW_MMapTitle*)widg)->align;
9687 break;
9688 default:
9689 bad_subwidg_type(false, ty);
9690 ret = -10000;
9691 break;
9692 }
9693 }
9694 break;
9695 }
9696 case SUBWIDGTY_SHADOWTY:
9697 {
9698 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9699 {
9700 auto ty = widg->getType();
9701 switch(ty)
9702 {
9703 case widgTEXT:
9704 ret = 10000*((SW_Text*)widg)->shadtype;
9705 break;
9706 case widgTEXTBOX:
9707 ret = 10000*((SW_TextBox*)widg)->shadtype;
9708 break;
9709 case widgSELECTEDTEXT:
9710 ret = 10000*((SW_SelectedText*)widg)->shadtype;
9711 break;
9712 case widgTIME:
9713 ret = 10000*((SW_Time*)widg)->shadtype;
9714 break;
9715 case widgCOUNTER:
9716 ret = 10000*((SW_Counter*)widg)->shadtype;
9717 break;
9718 case widgBTNCOUNTER:
9719 ret = 10000*((SW_BtnCounter*)widg)->shadtype;
9720 break;
9721 case widgOLDCTR:
9722 ret = 10000*((SW_Counters*)widg)->shadtype;
9723 break;
9724 case widgMMAPTITLE:
9725 ret = 10000*((SW_MMapTitle*)widg)->shadtype;
9726 break;
9727 default:
9728 bad_subwidg_type(false, ty);
9729 ret = -10000;
9730 break;
9731 }
9732 }
9733 break;
9734 }
9735 case SUBWIDGTY_COLOR_TXT:
9736 {
9737 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9738 {
9739 auto ty = widg->getType();
9740 switch(ty)
9741 {
9742 case widgTEXT:
9743 ret = 10000*((SW_Text*)widg)->c_text.get_int_color();
9744 break;
9745 case widgTEXTBOX:
9746 ret = 10000*((SW_TextBox*)widg)->c_text.get_int_color();
9747 break;
9748 case widgSELECTEDTEXT:
9749 ret = 10000*((SW_SelectedText*)widg)->c_text.get_int_color();
9750 break;
9751 case widgTIME:
9752 ret = 10000*((SW_Time*)widg)->c_text.get_int_color();
9753 break;
9754 case widgCOUNTER:
9755 ret = 10000*((SW_Counter*)widg)->c_text.get_int_color();
9756 break;
9757 case widgBTNCOUNTER:
9758 ret = 10000*((SW_BtnCounter*)widg)->c_text.get_int_color();
9759 break;
9760 case widgOLDCTR:
9761 ret = 10000*((SW_Counters*)widg)->c_text.get_int_color();
9762 break;
9763 case widgMMAPTITLE:
9764 ret = 10000*((SW_MMapTitle*)widg)->c_text.get_int_color();
9765 break;
9766 case widgMCGUFF_FRAME:
9767 ret = 10000*((SW_TriFrame*)widg)->c_number.get_int_color();
9768 break;
9769 default:
9770 bad_subwidg_type(false, ty);
9771 break;
9772 }
9773 }
9774 break;
9775 }
9776 case SUBWIDGTY_COLOR_SHD:
9777 {
9778 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9779 {
9780 auto ty = widg->getType();
9781 switch(ty)
9782 {
9783 case widgTEXT:
9784 ret = 10000*((SW_Text*)widg)->c_shadow.get_int_color();
9785 break;
9786 case widgTEXTBOX:
9787 ret = 10000*((SW_TextBox*)widg)->c_shadow.get_int_color();
9788 break;
9789 case widgSELECTEDTEXT:
9790 ret = 10000*((SW_SelectedText*)widg)->c_shadow.get_int_color();
9791 break;
9792 case widgTIME:
9793 ret = 10000*((SW_Time*)widg)->c_shadow.get_int_color();
9794 break;
9795 case widgCOUNTER:
9796 ret = 10000*((SW_Counter*)widg)->c_shadow.get_int_color();
9797 break;
9798 case widgBTNCOUNTER:
9799 ret = 10000*((SW_BtnCounter*)widg)->c_shadow.get_int_color();
9800 break;
9801 case widgOLDCTR:
9802 ret = 10000*((SW_Counters*)widg)->c_shadow.get_int_color();
9803 break;
9804 case widgMMAPTITLE:
9805 ret = 10000*((SW_MMapTitle*)widg)->c_shadow.get_int_color();
9806 break;
9807 default:
9808 bad_subwidg_type(false, ty);
9809 break;
9810 }
9811 }
9812 break;
9813 }
9814 case SUBWIDGTY_COLOR_BG:
9815 {
9816 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9817 {
9818 auto ty = widg->getType();
9819 switch(ty)
9820 {
9821 case widgTEXT:
9822 ret = 10000*((SW_Text*)widg)->c_bg.get_int_color();
9823 break;
9824 case widgTEXTBOX:
9825 ret = 10000*((SW_TextBox*)widg)->c_bg.get_int_color();
9826 break;
9827 case widgSELECTEDTEXT:
9828 ret = 10000*((SW_SelectedText*)widg)->c_bg.get_int_color();
9829 break;
9830 case widgTIME:
9831 ret = 10000*((SW_Time*)widg)->c_bg.get_int_color();
9832 break;
9833 case widgCOUNTER:
9834 ret = 10000*((SW_Counter*)widg)->c_bg.get_int_color();
9835 break;
9836 case widgBTNCOUNTER:
9837 ret = 10000*((SW_BtnCounter*)widg)->c_bg.get_int_color();
9838 break;
9839 case widgOLDCTR:
9840 ret = 10000*((SW_Counters*)widg)->c_bg.get_int_color();
9841 break;
9842 case widgMMAPTITLE:
9843 ret = 10000*((SW_MMapTitle*)widg)->c_bg.get_int_color();
9844 break;
9845 case widgBGCOLOR:
9846 ret = 10000*((SW_Clear*)widg)->c_bg.get_int_color();
9847 break;
9848 case widgCOUNTERPERCBAR:
9849 ret = 10000*((SW_CounterPercentBar*)widg)->c_bg.get_int_color();
9850 break;
9851 default:
9852 bad_subwidg_type(false, ty);
9853 break;
9854 }
9855 }
9856 break;
9857 }
9858
9859 case SUBWIDGTY_COLOR_TXT2:
9860 {
9861 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9862 {
9863 auto ty = widg->getType();
9864 switch(ty)
9865 {
9866 case widgCOUNTER:
9867 ret = 10000*((SW_Counter*)widg)->c_text2.get_int_color();
9868 break;
9869 case widgBTNCOUNTER:
9870 ret = 10000*((SW_BtnCounter*)widg)->c_text2.get_int_color();
9871 break;
9872 default:
9873 bad_subwidg_type(false, ty);
9874 break;
9875 }
9876 }
9877 break;
9878 }
9879 case SUBWIDGTY_COLOR_SHD2:
9880 {
9881 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9882 {
9883 auto ty = widg->getType();
9884 switch(ty)
9885 {
9886 case widgCOUNTER:
9887 ret = 10000*((SW_Counter*)widg)->c_shadow2.get_int_color();
9888 break;
9889 case widgBTNCOUNTER:
9890 ret = 10000*((SW_BtnCounter*)widg)->c_shadow2.get_int_color();
9891 break;
9892 default:
9893 bad_subwidg_type(false, ty);
9894 break;
9895 }
9896 }
9897 break;
9898 }
9899 case SUBWIDGTY_COLOR_BG2:
9900 {
9901 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9902 {
9903 auto ty = widg->getType();
9904 switch(ty)
9905 {
9906 case widgCOUNTER:
9907 ret = 10000*((SW_Counter*)widg)->c_bg2.get_int_color();
9908 break;
9909 case widgBTNCOUNTER:
9910 ret = 10000*((SW_BtnCounter*)widg)->c_bg2.get_int_color();
9911 break;
9912 default:
9913 bad_subwidg_type(false, ty);
9914 break;
9915 }
9916 }
9917 break;
9918 }
9919 case SUBWIDGTY_COLOR_OLINE:
9920 {
9921 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9922 {
9923 auto ty = widg->getType();
9924 switch(ty)
9925 {
9926 case widgLINE:
9927 ret = 10000*((SW_Line*)widg)->c_line.get_int_color();
9928 break;
9929 case widgRECT:
9930 ret = 10000*((SW_Rect*)widg)->c_outline.get_int_color();
9931 break;
9932 case widgMCGUFF_FRAME:
9933 ret = 10000*((SW_TriFrame*)widg)->c_outline.get_int_color();
9934 break;
9935 default:
9936 bad_subwidg_type(false, ty);
9937 break;
9938 }
9939 }
9940 break;
9941 }
9942 case SUBWIDGTY_COLOR_FILL:
9943 {
9944 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9945 {
9946 auto ty = widg->getType();
9947 switch(ty)
9948 {
9949 case widgRECT:
9950 ret = 10000*((SW_Rect*)widg)->c_fill.get_int_color();
9951 break;
9952 case widgCOUNTERPERCBAR:
9953 ret = 10000*((SW_CounterPercentBar*)widg)->c_fill.get_int_color();
9954 break;
9955 default:
9956 bad_subwidg_type(false, ty);
9957 break;
9958 }
9959 }
9960 break;
9961 }
9962 case SUBWIDGTY_BUTTON:
9963 {
9964 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9965 {
9966 auto ty = widg->getType();
9967 switch(ty)
9968 {
9969 case widgBTNITM:
9970 ret = 10000*((SW_ButtonItem*)widg)->btn;
9971 break;
9972 case widgBTNCOUNTER:
9973 ret = 10000*((SW_BtnCounter*)widg)->btn;
9974 break;
9975 default:
9976 bad_subwidg_type(false, ty);
9977 ret = -10000;
9978 break;
9979 }
9980 }
9981 break;
9982 }
9983 case SUBWIDGTY_MINDIG:
9984 {
9985 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9986 {
9987 auto ty = widg->getType();
9988 switch(ty)
9989 {
9990 case widgCOUNTER:
9991 ret = 10000*((SW_Counter*)widg)->mindigits;
9992 break;
9993 case widgBTNCOUNTER:
9994 ret = 10000*((SW_BtnCounter*)widg)->mindigits;
9995 break;
9996 case widgOLDCTR:
9997 ret = 10000*((SW_Counters*)widg)->digits;
9998 break;
9999 default:
10000 bad_subwidg_type(false, ty);
10001 ret = -10000;
10002 break;
10003 }
10004 }
10005 break;
10006 }
10007 case SUBWIDGTY_MAXDIG:
10008 {
10009 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10010 {
10011 auto ty = widg->getType();
10012 switch(ty)
10013 {
10014 case widgCOUNTER:
10015 ret = 10000*((SW_Counter*)widg)->maxdigits;
10016 break;
10017 case widgBTNCOUNTER:
10018 ret = 10000*((SW_BtnCounter*)widg)->maxdigits;
10019 break;
10020 default:
10021 bad_subwidg_type(false, ty);
10022 ret = -10000;
10023 break;
10024 }
10025 }
10026 break;
10027 }
10028 case SUBWIDGTY_INFITM:
10029 {
10030 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10031 {
10032 auto ty = widg->getType();
10033 switch(ty)
10034 {
10035 case widgCOUNTER:
10036 ret = 10000*((SW_Counter*)widg)->infitm;
10037 break;
10038 case widgOLDCTR:
10039 ret = 10000*((SW_Counters*)widg)->infitm;
10040 break;
10041 case widgLGAUGE:
10042 case widgMGAUGE:
10043 case widgMISCGAUGE:
10044 ret = 10000*((SW_GaugePiece*)widg)->inf_item;
10045 break;
10046 default:
10047 bad_subwidg_type(false, ty);
10048 ret = -10000;
10049 break;
10050 }
10051 }
10052 break;
10053 }
10054 case SUBWIDGTY_INFCHAR:
10055 {
10056 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10057 {
10058 auto ty = widg->getType();
10059 switch(ty)
10060 {
10061 case widgCOUNTER:
10062 ret = 10000*byte(((SW_Counter*)widg)->infchar);
10063 break;
10064 case widgOLDCTR:
10065 ret = 10000*byte(((SW_Counters*)widg)->infchar);
10066 break;
10067 case widgBTNCOUNTER:
10068 ret = 10000*byte(((SW_BtnCounter*)widg)->infchar);
10069 break;
10070 default:
10071 bad_subwidg_type(false, ty);
10072 break;
10073 }
10074 }
10075 break;
10076 }
10077 case SUBWIDGTY_COSTIND:
10078 {
10079 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10080 {
10081 auto ty = widg->getType();
10082 switch(ty)
10083 {
10084 case widgBTNCOUNTER:
10085 ret = 10000*((SW_BtnCounter*)widg)->costind;
10086 break;
10087 default:
10088 bad_subwidg_type(false, ty);
10089 ret = -1;
10090 break;
10091 }
10092 }
10093 break;
10094 }
10095 case SUBWIDGTY_COLOR_PLAYER:
10096 {
10097 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10098 {
10099 auto ty = widg->getType();
10100 switch(ty)
10101 {
10102 case widgMMAP:
10103 ret = 10000*((SW_MMap*)widg)->c_plr.get_int_color();
10104 break;
10105 case widgLMAP:
10106 ret = 10000*((SW_LMap*)widg)->c_plr.get_int_color();
10107 break;
10108 default:
10109 bad_subwidg_type(false, ty);
10110 break;
10111 }
10112 }
10113 break;
10114 }
10115 case SUBWIDGTY_COLOR_CMPBLNK:
10116 {
10117 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10118 {
10119 auto ty = widg->getType();
10120 switch(ty)
10121 {
10122 case widgMMAP:
10123 ret = 10000*((SW_MMap*)widg)->c_cmp_blink.get_int_color();
10124 break;
10125 default:
10126 bad_subwidg_type(false, ty);
10127 break;
10128 }
10129 }
10130 break;
10131 }
10132 case SUBWIDGTY_COLOR_CMPOFF:
10133 {
10134 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10135 {
10136 auto ty = widg->getType();
10137 switch(ty)
10138 {
10139 case widgMMAP:
10140 ret = 10000*((SW_MMap*)widg)->c_cmp_off.get_int_color();
10141 break;
10142 default:
10143 bad_subwidg_type(false, ty);
10144 break;
10145 }
10146 }
10147 break;
10148 }
10149 case SUBWIDGTY_COLOR_ROOM:
10150 {
10151 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10152 {
10153 auto ty = widg->getType();
10154 switch(ty)
10155 {
10156 case widgLMAP:
10157 ret = 10000*((SW_LMap*)widg)->c_room.get_int_color();
10158 break;
10159 default:
10160 bad_subwidg_type(false, ty);
10161 break;
10162 }
10163 }
10164 break;
10165 }
10166 case SUBWIDGTY_ITEMCLASS:
10167 {
10168 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10169 {
10170 auto ty = widg->getType();
10171 switch(ty)
10172 {
10173 case widgITEMSLOT:
10174 ret = 10000*((SW_ItemSlot*)widg)->iclass;
10175 break;
10176 default:
10177 bad_subwidg_type(false, ty);
10178 break;
10179 }
10180 }
10181 break;
10182 }
10183 case SUBWIDGTY_ITEMID:
10184 {
10185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10186 {
10187 1455 auto ty = widg->getType();
10188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 switch(ty)
10189 {
10190 case widgITEMSLOT:
10191 1455 ret = 10000*((SW_ItemSlot*)widg)->iid;
10192 1455 break;
10193 default:
10194 bad_subwidg_type(false, ty);
10195 break;
10196 }
10197 1455 }
10198 1455 break;
10199 }
10200 case SUBWIDGTY_FRAMETILE:
10201 {
10202 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10203 {
10204 auto ty = widg->getType();
10205 switch(ty)
10206 {
10207 case widgMCGUFF_FRAME:
10208 ret = 10000*((SW_TriFrame*)widg)->frame_tile;
10209 break;
10210 default:
10211 bad_subwidg_type(false, ty);
10212 break;
10213 }
10214 }
10215 break;
10216 }
10217 case SUBWIDGTY_FRAMECSET:
10218 {
10219 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10220 {
10221 auto ty = widg->getType();
10222 switch(ty)
10223 {
10224 case widgMCGUFF_FRAME:
10225 ret = 10000*((SW_TriFrame*)widg)->frame_cset;
10226 break;
10227 default:
10228 bad_subwidg_type(false, ty);
10229 break;
10230 }
10231 }
10232 break;
10233 }
10234 case SUBWIDGTY_PIECETILE:
10235 {
10236 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10237 {
10238 auto ty = widg->getType();
10239 switch(ty)
10240 {
10241 case widgMCGUFF_FRAME:
10242 ret = 10000*((SW_TriFrame*)widg)->piece_tile;
10243 break;
10244 default:
10245 bad_subwidg_type(false, ty);
10246 break;
10247 }
10248 }
10249 break;
10250 }
10251 case SUBWIDGTY_PIECECSET:
10252 {
10253 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10254 {
10255 auto ty = widg->getType();
10256 switch(ty)
10257 {
10258 case widgMCGUFF_FRAME:
10259 ret = 10000*((SW_TriFrame*)widg)->piece_cset;
10260 break;
10261 default:
10262 bad_subwidg_type(false, ty);
10263 break;
10264 }
10265 }
10266 break;
10267 }
10268 case SUBWIDGTY_FLIP:
10269 {
10270 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10271 {
10272 auto ty = widg->getType();
10273 switch(ty)
10274 {
10275 case widgMCGUFF:
10276 ret = 10000*((SW_McGuffin*)widg)->flip;
10277 break;
10278 case widgTILEBLOCK:
10279 ret = 10000*((SW_TileBlock*)widg)->flip;
10280 break;
10281 case widgMINITILE:
10282 ret = 10000*((SW_MiniTile*)widg)->flip;
10283 break;
10284 default:
10285 bad_subwidg_type(false, ty);
10286 break;
10287 }
10288 }
10289 break;
10290 }
10291 case SUBWIDGTY_NUMBER:
10292 {
10293 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10294 {
10295 auto ty = widg->getType();
10296 switch(ty)
10297 {
10298 case widgMCGUFF:
10299 ret = 10000*((SW_McGuffin*)widg)->number;
10300 break;
10301 default:
10302 bad_subwidg_type(false, ty);
10303 break;
10304 }
10305 }
10306 break;
10307 }
10308 case SUBWIDGTY_FRAMES:
10309 {
10310 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10311 {
10312 auto ty = widg->getType();
10313 switch(ty)
10314 {
10315 case widgLGAUGE:
10316 case widgMGAUGE:
10317 case widgMISCGAUGE:
10318 ret = 10000*((SW_GaugePiece*)widg)->frames;
10319 break;
10320 default:
10321 bad_subwidg_type(false, ty);
10322 ret = -10000;
10323 break;
10324 }
10325 }
10326 break;
10327 }
10328 case SUBWIDGTY_SPEED:
10329 {
10330 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10331 {
10332 auto ty = widg->getType();
10333 switch(ty)
10334 {
10335 case widgLGAUGE:
10336 case widgMGAUGE:
10337 case widgMISCGAUGE:
10338 ret = 10000*((SW_GaugePiece*)widg)->speed;
10339 break;
10340 default:
10341 bad_subwidg_type(false, ty);
10342 ret = -10000;
10343 break;
10344 }
10345 }
10346 break;
10347 }
10348 case SUBWIDGTY_DELAY:
10349 {
10350 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10351 {
10352 auto ty = widg->getType();
10353 switch(ty)
10354 {
10355 case widgLGAUGE:
10356 case widgMGAUGE:
10357 case widgMISCGAUGE:
10358 ret = 10000*((SW_GaugePiece*)widg)->delay;
10359 break;
10360 default:
10361 bad_subwidg_type(false, ty);
10362 ret = -10000;
10363 break;
10364 }
10365 }
10366 break;
10367 }
10368 case SUBWIDGTY_CONTAINER:
10369 {
10370 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10371 {
10372 auto ty = widg->getType();
10373 switch(ty)
10374 {
10375 case widgLGAUGE:
10376 case widgMGAUGE:
10377 case widgMISCGAUGE:
10378 ret = 10000*((SW_GaugePiece*)widg)->container;
10379 break;
10380 default:
10381 bad_subwidg_type(false, ty);
10382 ret = -10000;
10383 break;
10384 }
10385 }
10386 break;
10387 }
10388 case SUBWIDGTY_GAUGE_WID:
10389 {
10390 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10391 {
10392 auto ty = widg->getType();
10393 switch(ty)
10394 {
10395 case widgLGAUGE:
10396 case widgMGAUGE:
10397 case widgMISCGAUGE:
10398 ret = 10000*(((SW_GaugePiece*)widg)->gauge_wid+1);
10399 break;
10400 default:
10401 bad_subwidg_type(false, ty);
10402 ret = -10000;
10403 break;
10404 }
10405 }
10406 break;
10407 }
10408 case SUBWIDGTY_GAUGE_HEI:
10409 {
10410 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10411 {
10412 auto ty = widg->getType();
10413 switch(ty)
10414 {
10415 case widgLGAUGE:
10416 case widgMGAUGE:
10417 case widgMISCGAUGE:
10418 ret = 10000*(((SW_GaugePiece*)widg)->gauge_hei+1);
10419 break;
10420 default:
10421 bad_subwidg_type(false, ty);
10422 ret = -10000;
10423 break;
10424 }
10425 }
10426 break;
10427 }
10428 case SUBWIDGTY_UNITS:
10429 {
10430 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10431 {
10432 auto ty = widg->getType();
10433 switch(ty)
10434 {
10435 case widgLGAUGE:
10436 case widgMGAUGE:
10437 case widgMISCGAUGE:
10438 ret = 10000*(((SW_GaugePiece*)widg)->unit_per_frame+1);
10439 break;
10440 default:
10441 bad_subwidg_type(false, ty);
10442 ret = -10000;
10443 break;
10444 }
10445 }
10446 break;
10447 }
10448 case SUBWIDGTY_HSPACE:
10449 {
10450 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10451 {
10452 auto ty = widg->getType();
10453 switch(ty)
10454 {
10455 case widgLGAUGE:
10456 case widgMGAUGE:
10457 case widgMISCGAUGE:
10458 ret = 10000*((SW_GaugePiece*)widg)->hspace;
10459 break;
10460 default:
10461 bad_subwidg_type(false, ty);
10462 ret = -10000;
10463 break;
10464 }
10465 }
10466 break;
10467 }
10468 case SUBWIDGTY_VSPACE:
10469 {
10470 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10471 {
10472 auto ty = widg->getType();
10473 switch(ty)
10474 {
10475 case widgLGAUGE:
10476 case widgMGAUGE:
10477 case widgMISCGAUGE:
10478 ret = 10000*((SW_GaugePiece*)widg)->vspace;
10479 break;
10480 default:
10481 bad_subwidg_type(false, ty);
10482 ret = -10000;
10483 break;
10484 }
10485 }
10486 break;
10487 }
10488 case SUBWIDGTY_GRIDX:
10489 {
10490 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10491 {
10492 auto ty = widg->getType();
10493 switch(ty)
10494 {
10495 case widgLGAUGE:
10496 case widgMGAUGE:
10497 case widgMISCGAUGE:
10498 ret = 10000*((SW_GaugePiece*)widg)->grid_xoff;
10499 break;
10500 default:
10501 bad_subwidg_type(false, ty);
10502 ret = -10000;
10503 break;
10504 }
10505 }
10506 break;
10507 }
10508 case SUBWIDGTY_GRIDY:
10509 {
10510 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10511 {
10512 auto ty = widg->getType();
10513 switch(ty)
10514 {
10515 case widgLGAUGE:
10516 case widgMGAUGE:
10517 case widgMISCGAUGE:
10518 ret = 10000*((SW_GaugePiece*)widg)->grid_yoff;
10519 break;
10520 default:
10521 bad_subwidg_type(false, ty);
10522 ret = -10000;
10523 break;
10524 }
10525 }
10526 break;
10527 }
10528 case SUBWIDGTY_ANIMVAL:
10529 {
10530 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10531 {
10532 auto ty = widg->getType();
10533 switch(ty)
10534 {
10535 case widgLGAUGE:
10536 case widgMGAUGE:
10537 case widgMISCGAUGE:
10538 ret = 10000*((SW_GaugePiece*)widg)->anim_val;
10539 break;
10540 default:
10541 bad_subwidg_type(false, ty);
10542 ret = -10000;
10543 break;
10544 }
10545 }
10546 break;
10547 }
10548 case SUBWIDGTY_SHOWDRAIN:
10549 {
10550 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10551 {
10552 auto ty = widg->getType();
10553 switch(ty)
10554 {
10555 case widgMGAUGE:
10556 ret = 10000*((SW_MagicGaugePiece*)widg)->showdrain;
10557 break;
10558 default:
10559 bad_subwidg_type(false, ty);
10560 ret = -10000;
10561 break;
10562 }
10563 }
10564 break;
10565 }
10566 case SUBWIDGTY_PERCONTAINER:
10567 {
10568 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10569 {
10570 auto ty = widg->getType();
10571 switch(ty)
10572 {
10573 case widgMISCGAUGE:
10574 ret = 10000*((SW_MiscGaugePiece*)widg)->per_container;
10575 break;
10576 default:
10577 bad_subwidg_type(false, ty);
10578 ret = -10000;
10579 break;
10580 }
10581 }
10582 break;
10583 }
10584 case SUBWIDGTY_TABSIZE:
10585 {
10586 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10587 {
10588 auto ty = widg->getType();
10589 switch(ty)
10590 {
10591 case widgTEXTBOX:
10592 ret = 10000*((SW_TextBox*)widg)->tabsize;
10593 break;
10594 case widgSELECTEDTEXT:
10595 ret = 10000*((SW_SelectedText*)widg)->tabsize;
10596 break;
10597 default:
10598 bad_subwidg_type(false, ty);
10599 ret = -10000;
10600 break;
10601 }
10602 }
10603 break;
10604 }
10605 case SUBWIDGTY_LITEMS:
10606 {
10607 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10608 {
10609 auto ty = widg->getType();
10610 switch(ty)
10611 {
10612 case widgMMAP:
10613 ret = 10000*((SW_MMap*)widg)->compass_litems;
10614 break;
10615 default:
10616 bad_subwidg_type(false, ty);
10617 ret = -10000;
10618 break;
10619 }
10620 }
10621 break;
10622 }
10623
10624 default:
10625 {
10626
2/2
✓ Branch 0 taken 394576463 times.
✓ Branch 1 taken 237946194 times.
632522657 if (zasm_array_supports(arg))
10627 {
10628 394576463 int ref_arg = get_register_ref_dependency(arg).value_or(0);
10629
2/2
✓ Branch 0 taken 218361338 times.
✓ Branch 1 taken 176215125 times.
394576463 int ref = ref_arg ? get_ref(ref_arg) : 0;
10630 394576463 ret = zasm_array_get(arg, ref, ri->d[rINDEX] / 10000);
10631 394576463 }
10632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 237946194 times.
237946194 else if (auto r = scripting_engine_get_register(arg))
10633 237946194 ret = *r;
10634 632522657 break;
10635 }
10636 }
10637
10638 2918301009 current_zasm_register = 0;
10639
10640 2918301009 return ret;
10641 7365563285 }
10642
10643 //Setter Instructions
10644
10645
10646 5946899392 void set_register(int32_t arg, int32_t value)
10647 {
10648
3/4
✓ Branch 0 taken 5946899392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1645506159 times.
✓ Branch 3 taken 4301393233 times.
5946899392 if (arg >= D(0) && arg <= D(7))
10649 {
10650 4301393233 ri->d[arg - D(0)] = value;
10651 4301393233 return;
10652 }
10653
4/4
✓ Branch 0 taken 1611972691 times.
✓ Branch 1 taken 33533468 times.
✓ Branch 2 taken 1589557346 times.
✓ Branch 3 taken 22415345 times.
1645506159 else if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
10654 {
10655 22415345 game->global_d[arg-GD(0)] = value;
10656 22415345 return;
10657 }
10658
10659 //Macros
10660
10661 #define SET_SPRITEDATA_VAR_INT(member, str) \
10662 { \
10663 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
10664 { \
10665 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
10666 } \
10667 else \
10668 { \
10669 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,214747); \
10670 } \
10671 } \
10672
10673 #define SET_SPRITEDATA_VAR_BYTE(member, str) \
10674 { \
10675 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
10676 { \
10677 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
10678 } \
10679 else \
10680 { \
10681 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,255); \
10682 } \
10683 } \
10684
10685 1623090814 current_zasm_register = arg;
10686
10687 // Do not ever use `return` in these cases!
10688
221/975
✓ Branch 0 taken 4499476 times.
✓ Branch 1 taken 13958 times.
✓ Branch 2 taken 2047856 times.
✓ Branch 3 taken 3677 times.
✓ Branch 4 taken 2299966 times.
✓ Branch 5 taken 2299127 times.
✓ Branch 6 taken 13915 times.
✓ Branch 7 taken 14193 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 14323 times.
✓ Branch 10 taken 4147 times.
✓ Branch 11 taken 4149 times.
✓ Branch 12 taken 13890 times.
✓ Branch 13 taken 13913 times.
✓ Branch 14 taken 811 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 76581 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 60 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 48 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 837 times.
✓ Branch 25 taken 2288 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 5878 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 277656 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 4859 times.
✓ Branch 36 taken 3652 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✓ Branch 42 taken 4 times.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1121819 times.
✓ Branch 56 taken 646198 times.
✓ Branch 57 taken 298036 times.
✓ Branch 58 taken 295303 times.
✓ Branch 59 taken 281894 times.
✓ Branch 60 taken 186826 times.
✓ Branch 61 taken 118163 times.
✓ Branch 62 taken 118214 times.
✓ Branch 63 taken 262073 times.
✓ Branch 64 taken 262073 times.
✓ Branch 65 taken 262073 times.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 1121819 times.
✓ Branch 69 taken 261563 times.
✓ Branch 70 taken 261555 times.
✓ Branch 71 taken 261628 times.
✓ Branch 72 taken 261662 times.
✓ Branch 73 taken 177542 times.
✓ Branch 74 taken 111830 times.
✓ Branch 75 taken 115219 times.
✓ Branch 76 taken 115270 times.
✓ Branch 77 taken 262073 times.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✓ Branch 94 taken 214057 times.
✓ Branch 95 taken 1 times.
✓ Branch 96 taken 214043 times.
✓ Branch 97 taken 971 times.
✓ Branch 98 taken 408 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 71609 times.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✓ Branch 103 taken 9786 times.
✗ Branch 104 not taken.
✓ Branch 105 taken 6 times.
✓ Branch 106 taken 1181 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 1131 times.
✓ Branch 109 taken 76041 times.
✗ Branch 110 not taken.
✓ Branch 111 taken 2464 times.
✓ Branch 112 taken 3263 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 26540 times.
✓ Branch 115 taken 6 times.
✓ Branch 116 taken 429 times.
✓ Branch 117 taken 6 times.
✓ Branch 118 taken 6 times.
✓ Branch 119 taken 885 times.
✓ Branch 120 taken 839 times.
✓ Branch 121 taken 2345 times.
✓ Branch 122 taken 6 times.
✓ Branch 123 taken 71310 times.
✓ Branch 124 taken 71308 times.
✓ Branch 125 taken 1768 times.
✗ Branch 126 not taken.
✓ Branch 127 taken 6 times.
✓ Branch 128 taken 72525 times.
✓ Branch 129 taken 6 times.
✓ Branch 130 taken 833 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 42 times.
✓ Branch 133 taken 1130 times.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✓ Branch 136 taken 527 times.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✓ Branch 145 taken 390183 times.
✓ Branch 146 taken 1 times.
✓ Branch 147 taken 390780 times.
✓ Branch 148 taken 57530 times.
✓ Branch 149 taken 55587 times.
✗ Branch 150 not taken.
✓ Branch 151 taken 227256 times.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✓ Branch 157 taken 114186 times.
✓ Branch 158 taken 74446 times.
✓ Branch 159 taken 178 times.
✓ Branch 160 taken 35337 times.
✓ Branch 161 taken 41 times.
✓ Branch 162 taken 1039 times.
✓ Branch 163 taken 549 times.
✓ Branch 164 taken 78832 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 193736 times.
✓ Branch 167 taken 84994 times.
✓ Branch 168 taken 44193 times.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✓ Branch 172 taken 325611 times.
✓ Branch 173 taken 325024 times.
✓ Branch 174 taken 44 times.
✓ Branch 175 taken 202345 times.
✓ Branch 176 taken 202345 times.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✓ Branch 190 taken 6 times.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✓ Branch 207 taken 30 times.
✓ Branch 208 taken 30 times.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✓ Branch 217 taken 900 times.
✓ Branch 218 taken 7396 times.
✓ Branch 219 taken 6502 times.
✗ Branch 220 not taken.
✓ Branch 221 taken 11 times.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✓ Branch 227 taken 5310 times.
✓ Branch 228 taken 114 times.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✗ Branch 257 not taken.
✗ Branch 258 not taken.
✓ Branch 259 taken 20 times.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✓ Branch 266 taken 5120 times.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✗ Branch 273 not taken.
✓ Branch 274 taken 3225 times.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✓ Branch 353 taken 444726 times.
✓ Branch 354 taken 2239361 times.
✓ Branch 355 taken 6367264 times.
✓ Branch 356 taken 12117383 times.
✓ Branch 357 taken 46788128 times.
✓ Branch 358 taken 162664402 times.
✓ Branch 359 taken 88305847 times.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✓ Branch 362 taken 64 times.
✓ Branch 363 taken 410111 times.
✓ Branch 364 taken 1 times.
✓ Branch 365 taken 77218 times.
✓ Branch 366 taken 10 times.
✗ Branch 367 not taken.
✓ Branch 368 taken 8474727 times.
✓ Branch 369 taken 284 times.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✓ Branch 372 taken 109743 times.
✓ Branch 373 taken 20806 times.
✓ Branch 374 taken 449481 times.
✓ Branch 375 taken 3393 times.
✓ Branch 376 taken 1119 times.
✓ Branch 377 taken 121 times.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✓ Branch 397 taken 11 times.
✓ Branch 398 taken 11 times.
✓ Branch 399 taken 11 times.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✗ Branch 402 not taken.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✗ Branch 407 not taken.
✓ Branch 408 taken 132 times.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 417 not taken.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✓ Branch 454 taken 531793831 times.
✗ Branch 455 not taken.
✓ Branch 456 taken 43783225 times.
✓ Branch 457 taken 16031 times.
✗ Branch 458 not taken.
✓ Branch 459 taken 477697 times.
✗ Branch 460 not taken.
✓ Branch 461 taken 497243 times.
✓ Branch 462 taken 2779 times.
✓ Branch 463 taken 97670 times.
✓ Branch 464 taken 2220 times.
✗ Branch 465 not taken.
✓ Branch 466 taken 283431 times.
✓ Branch 467 taken 14290 times.
✓ Branch 468 taken 5110 times.
✗ Branch 469 not taken.
✓ Branch 470 taken 952 times.
✗ Branch 471 not taken.
✗ Branch 472 not taken.
✓ Branch 473 taken 718 times.
✓ Branch 474 taken 1 times.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✗ Branch 477 not taken.
✓ Branch 478 taken 26326 times.
✓ Branch 479 taken 388698 times.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 482 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✓ Branch 487 taken 3 times.
✓ Branch 488 taken 277656 times.
✓ Branch 489 taken 93759 times.
✓ Branch 490 taken 93760 times.
✓ Branch 491 taken 93772 times.
✓ Branch 492 taken 93778 times.
✗ Branch 493 not taken.
✗ Branch 494 not taken.
✗ Branch 495 not taken.
✓ Branch 496 taken 290 times.
✓ Branch 497 taken 2578 times.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✓ Branch 513 taken 281941 times.
✓ Branch 514 taken 120700 times.
✓ Branch 515 taken 262073 times.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✓ Branch 518 taken 646198 times.
✓ Branch 519 taken 262073 times.
✓ Branch 520 taken 262073 times.
✓ Branch 521 taken 262073 times.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✓ Branch 537 taken 2 times.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✓ Branch 569 taken 182 times.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✓ Branch 577 taken 2760 times.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✓ Branch 587 taken 94 times.
✗ Branch 588 not taken.
✓ Branch 589 taken 13 times.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✓ Branch 595 taken 1679 times.
✓ Branch 596 taken 6 times.
✓ Branch 597 taken 476 times.
✓ Branch 598 taken 153795 times.
✓ Branch 599 taken 527 times.
✓ Branch 600 taken 4922 times.
✓ Branch 601 taken 70954 times.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✓ Branch 604 taken 72542 times.
✓ Branch 605 taken 833 times.
✓ Branch 606 taken 18928 times.
✓ Branch 607 taken 12 times.
✓ Branch 608 taken 62002 times.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✓ Branch 619 taken 117 times.
✓ Branch 620 taken 372485 times.
✓ Branch 621 taken 220890 times.
✓ Branch 622 taken 208988 times.
✓ Branch 623 taken 5420 times.
✓ Branch 624 taken 12175 times.
✓ Branch 625 taken 210232 times.
✗ Branch 626 not taken.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✓ Branch 629 taken 41 times.
✓ Branch 630 taken 1104 times.
✓ Branch 631 taken 156969 times.
✓ Branch 632 taken 4552 times.
✓ Branch 633 taken 194229 times.
✓ Branch 634 taken 31616 times.
✓ Branch 635 taken 1621 times.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✓ Branch 639 taken 4 times.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✓ Branch 648 taken 4 times.
✓ Branch 649 taken 360 times.
✓ Branch 650 taken 360 times.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✓ Branch 673 taken 10 times.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✓ Branch 681 taken 27297 times.
✓ Branch 682 taken 536 times.
✓ Branch 683 taken 39294 times.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✓ Branch 692 taken 370 times.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✗ Branch 698 not taken.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✓ Branch 707 taken 9 times.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✓ Branch 719 taken 28 times.
✗ Branch 720 not taken.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✓ Branch 724 taken 24 times.
✓ Branch 725 taken 24 times.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✓ Branch 728 taken 24 times.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✗ Branch 876 not taken.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✗ Branch 880 not taken.
✗ Branch 881 not taken.
✗ Branch 882 not taken.
✗ Branch 883 not taken.
✗ Branch 884 not taken.
✗ Branch 885 not taken.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✗ Branch 888 not taken.
✗ Branch 889 not taken.
✗ Branch 890 not taken.
✗ Branch 891 not taken.
✗ Branch 892 not taken.
✗ Branch 893 not taken.
✗ Branch 894 not taken.
✗ Branch 895 not taken.
✗ Branch 896 not taken.
✗ Branch 897 not taken.
✗ Branch 898 not taken.
✗ Branch 899 not taken.
✗ Branch 900 not taken.
✗ Branch 901 not taken.
✗ Branch 902 not taken.
✗ Branch 903 not taken.
✗ Branch 904 not taken.
✗ Branch 905 not taken.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✗ Branch 908 not taken.
✗ Branch 909 not taken.
✗ Branch 910 not taken.
✗ Branch 911 not taken.
✗ Branch 912 not taken.
✗ Branch 913 not taken.
✗ Branch 914 not taken.
✗ Branch 915 not taken.
✗ Branch 916 not taken.
✗ Branch 917 not taken.
✗ Branch 918 not taken.
✗ Branch 919 not taken.
✗ Branch 920 not taken.
✓ Branch 921 taken 646324165 times.
✓ Branch 922 taken 43220119 times.
✓ Branch 923 taken 838813 times.
✗ Branch 924 not taken.
✓ Branch 925 taken 124 times.
✗ Branch 926 not taken.
✓ Branch 927 taken 103742 times.
✗ Branch 928 not taken.
✓ Branch 929 taken 7263 times.
✓ Branch 930 taken 38 times.
✗ Branch 931 not taken.
✗ Branch 932 not taken.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✓ Branch 946 taken 3 times.
✗ Branch 947 not taken.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✗ Branch 951 not taken.
✗ Branch 952 not taken.
✓ Branch 953 taken 11 times.
✗ Branch 954 not taken.
✗ Branch 955 not taken.
✓ Branch 956 taken 4247 times.
✗ Branch 957 not taken.
✗ Branch 958 not taken.
✗ Branch 959 not taken.
✗ Branch 960 not taken.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✗ Branch 963 not taken.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✗ Branch 966 not taken.
✗ Branch 967 not taken.
✗ Branch 968 not taken.
✗ Branch 969 not taken.
✗ Branch 970 not taken.
✗ Branch 971 not taken.
✗ Branch 972 not taken.
✗ Branch 973 not taken.
✗ Branch 974 not taken.
1623090814 switch(arg)
10689 {
10690 ///----------------------------------------------------------------------------------------------------//
10691 //FFC Variables
10692 case DATA:
10693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4499476 times.
4499476 if (auto ffc = ResolveFFC(ri->ffcref))
10694 {
10695 4499476 zc_ffc_set(*ffc, vbound(value/10000,0,MAXCOMBOS-1));
10696 4499476 }
10697 4499476 break;
10698
10699 case FFSCRIPT:
10700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13958 times.
13958 if (auto ffc = ResolveFFC(ri->ffcref))
10701 {
10702 13958 ffc->script = vbound(value/10000, 0, NUMSCRIPTFFC-1);
10703
2/2
✓ Branch 0 taken 223328 times.
✓ Branch 1 taken 13958 times.
237286 for(int32_t i=0; i<16; i++)
10704 223328 ffc->miscellaneous[i] = 0;
10705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13958 times.
13958 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
10706 {
10707
2/2
✓ Branch 0 taken 111664 times.
✓ Branch 1 taken 13958 times.
125622 for(int32_t i=0; i<8; i++)
10708 111664 ffc->initd[i] = 0;
10709 13958 }
10710 13958 on_reassign_script_engine_data(ScriptType::FFC, ffc->index);
10711 13958 }
10712 13958 break;
10713
10714
10715 case FCSET:
10716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2047856 times.
2047856 if (auto ffc = ResolveFFC(ri->ffcref))
10717 2047856 ffc->cset = (value/10000)&15;
10718 2047856 break;
10719
10720 case DELAY:
10721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3677 times.
3677 if (auto ffc = ResolveFFC(ri->ffcref))
10722 3677 ffc->delay = value/10000;
10723 3677 break;
10724
10725 case FX:
10726
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2299966 times.
2299966 if (auto ffc = ResolveFFC(ri->ffcref))
10727 2299966 ffc->x = zslongToFix(value);
10728 2299966 break;
10729
10730 case FY:
10731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2299127 times.
2299127 if (auto ffc = ResolveFFC(ri->ffcref))
10732 2299127 ffc->y=zslongToFix(value);
10733 2299127 break;
10734
10735 case XD:
10736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13915 times.
13915 if (auto ffc = ResolveFFC(ri->ffcref))
10737 13915 ffc->vx=zslongToFix(value);
10738 13915 break;
10739
10740 case YD:
10741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14193 times.
14193 if (auto ffc = ResolveFFC(ri->ffcref))
10742 14193 ffc->vy=zslongToFix(value);
10743 14193 break;
10744
10745 case FFCID:
10746 break;
10747
10748 case XD2:
10749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14323 times.
14323 if (auto ffc = ResolveFFC(ri->ffcref))
10750 14323 ffc->ax=zslongToFix(value);
10751 14323 break;
10752
10753 case YD2:
10754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16031 times.
16031 if (auto ffc = ResolveFFC(ri->ffcref))
10755 16031 ffc->ay=zslongToFix(value);
10756 16031 break;
10757
10758 case FFCWIDTH:
10759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4147 times.
4147 if (auto ffc = ResolveFFC(ri->ffcref))
10760 4147 ffc->hit_width = (value/10000);
10761 4147 break;
10762
10763 case FFCHEIGHT:
10764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4149 times.
4149 if (auto ffc = ResolveFFC(ri->ffcref))
10765 4149 ffc->hit_height = (value/10000);
10766 4149 break;
10767
10768 case FFTWIDTH:
10769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13890 times.
13890 if (auto ffc = ResolveFFC(ri->ffcref))
10770 13890 ffc->txsz = vbound(value/10000, 1, 4);
10771 13890 break;
10772
10773 case FFTHEIGHT:
10774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13913 times.
13913 if (auto ffc = ResolveFFC(ri->ffcref))
10775 13913 ffc->tysz = vbound(value/10000, 1, 4);
10776 13913 break;
10777
10778 case FFCLAYER:
10779 if (auto ffc = ResolveFFC(ri->ffcref))
10780 ffc->layer = vbound(value/10000, 0, 7);
10781 break;
10782
10783 case FFLINK:
10784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 811 times.
811 if (auto ffc = ResolveFFC(ri->ffcref))
10785 811 (ffc->link)=vbound(value/10000, 0, MAXFFCS-1); // Allow "ffc->Link = 0" to unlink ffc.
10786 //0 is none, setting this before made it impssible to clear it. -Z
10787 811 break;
10788
10789 case FFCLASTCHANGERX:
10790 if (auto ffc = ResolveFFC(ri->ffcref) )
10791 ffc->changer_x=vbound(zslongToFix(value).getInt(),-32768, 32767);
10792 break;
10793
10794 case FFCLASTCHANGERY:
10795 if (auto ffc = ResolveFFC(ri->ffcref) )
10796 ffc->changer_y=vbound(zslongToFix(value).getInt(),-32768, 32767);
10797 break;
10798
10799
10800
10801 ///----------------------------------------------------------------------------------------------------//
10802 //Hero's Variables
10803 case LINKX:
10804 {
10805
2/2
✓ Branch 0 taken 23258 times.
✓ Branch 1 taken 454439 times.
477697 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10806 {
10807 23258 Hero.setXfix(zslongToFix(value));
10808 23258 }
10809 else
10810 {
10811 454439 Hero.setX(value/10000);
10812 }
10813 }
10814 477697 break;
10815
10816 case LINKCSET:
10817 {
10818 Hero.cs = value/10000;
10819 break;
10820 }
10821 case LINKY:
10822 {
10823
2/2
✓ Branch 0 taken 22483 times.
✓ Branch 1 taken 474760 times.
497243 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10824 {
10825 22483 Hero.setYfix(zslongToFix(value));
10826 22483 }
10827 else
10828 {
10829 474760 Hero.setY(value/10000);
10830 }
10831 }
10832 497243 break;
10833
10834 case LINKZ:
10835 {
10836
2/2
✓ Branch 0 taken 2775 times.
✓ Branch 1 taken 4 times.
2779 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10837 {
10838 2775 Hero.setZfix(zslongToFix(value));
10839 2775 }
10840 else
10841 {
10842 4 Hero.setZ(value/10000);
10843 }
10844 }
10845 2779 break;
10846
10847 case LINKJUMP:
10848 76581 Hero.setJump(zslongToFix(value));
10849 76581 break;
10850
10851 case HEROFAKEJUMP:
10852 Hero.setFakeFall(zslongToFix(value) * -100);
10853 break;
10854
10855 case LINKDIR:
10856 {
10857 //Hero->setDir() calls reset_hookshot(), which removes the sword sprite.. O_o
10858
3/4
✓ Branch 0 taken 95484 times.
✓ Branch 1 taken 2186 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 95484 times.
97670 if(Hero.getAction() == attacking || Hero.getAction() == sideswimattacking) Hero.dir = (value/10000);
10859 95484 else Hero.setDir(value/10000);
10860
10861 97670 break;
10862 }
10863
10864 case LINKHITDIR:
10865 2220 Hero.setHitDir(value / 10000);
10866 2220 break;
10867
10868 case LINKGRAVITY:
10869 if(value)
10870 Hero.moveflags |= move_obeys_grav;
10871 else
10872 Hero.moveflags &= ~move_obeys_grav;
10873 break;
10874
10875 case HERONOSTEPFORWARD:
10876 FFCore.nostepforward = ( (value) ? 1 : 0 );
10877 break;
10878
10879 case LINKHP:
10880
6/6
✓ Branch 0 taken 177818 times.
✓ Branch 1 taken 105613 times.
✓ Branch 2 taken 283260 times.
✓ Branch 3 taken 171 times.
✓ Branch 4 taken 177647 times.
✓ Branch 5 taken 105613 times.
283431 game->set_life(zc_max(0, zc_min(value/10000,game->get_maxlife())));
10881 283431 break;
10882
10883 case LINKMP:
10884
6/6
✓ Branch 0 taken 6601 times.
✓ Branch 1 taken 7689 times.
✓ Branch 2 taken 14271 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 6582 times.
✓ Branch 5 taken 7689 times.
14290 game->set_magic(zc_max(0, zc_min(value/10000,game->get_maxmagic())));
10885 14290 break;
10886
10887 case LINKMAXHP:
10888 60 game->set_maxlife(value/10000);
10889 60 break;
10890
10891 case LINKMAXMP:
10892 game->set_maxmagic(value/10000);
10893 break;
10894
10895 case LINKACTION:
10896 {
10897 5110 int32_t act = value / 10000;
10898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5110 times.
5110 switch(act)
10899 {
10900 case hookshotout:
10901 case stunned:
10902 case ispushing:
10903 FFCore.setHeroAction(act);
10904 break;
10905 default:
10906 5110 Hero.setAction((actiontype)(act));
10907 5110 }
10908 //Protect from writing illegal actions to Hero's raw variable.
10909 //in the future, we can move all scripted actions that are not possible
10910 //to set in ZC into this mechanic. -Z
10911 5110 break;
10912 }
10913
10914 case HEROHEALTHBEEP:
10915 {
10916 int32_t beep = vbound((value/10000),-4, 255);
10917 //-2 suspends system control of stopping the sound
10918 //-3 suspends system control of stopping the sound AND suspends
10919 // system control over starting or playing it.
10920 heart_beep_timer = beep;
10921 if ( heart_beep_timer > -1 )
10922 {
10923 cont_sfx(QMisc.miscsfx[sfxLOWHEART]);
10924 }
10925 else
10926 {
10927 stop_sfx(QMisc.miscsfx[sfxLOWHEART]);
10928 }
10929 break;
10930 }
10931
10932 case LINKHELD:
10933 48 Hero.setHeldItem(vbound(value/10000,0,MAXITEMS-1));
10934 48 break;
10935
10936 case HEROSTEPRATE:
10937
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 if(!get_qr(qr_NEW_HERO_MOVEMENT))
10938 {
10939 Z_scripterrlog("To use '%s', you must %s the quest rule '%s'.", "Hero->Step", "enable", "New Hero Movement");
10940 }
10941
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 Hero.setStepRate(zc_max(value/10000,0));
10942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 952 times.
952 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
10943 952 zinit.heroStep = Hero.getStepRate();
10944 952 break;
10945 case HEROSHOVEOFFSET:
10946 if(!get_qr(qr_NEW_HERO_MOVEMENT2))
10947 Z_scripterrlog("To use 'Hero->ShoveOffset', you must enable the quest rule 'Newer Hero Movement'.");
10948 Hero.shove_offset = vbound(zslongToFix(value),16_zf,0_zf);
10949 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
10950 zinit.shove_offset = Hero.shove_offset;
10951 break;
10952
10953 case LINKEQUIP:
10954 {
10955 if ( FFCore.getQuestHeaderInfo(vZelda) == 0x250 && FFCore.getQuestHeaderInfo(vBuild) < 33 )
10956 {
10957 break;
10958 }
10959 //int32_t seta = (value/10000) >> 8; int32_t setb = value/10000) & 0xFF;
10960 int32_t setb = ((value/10000)&0xFF00)>>8, seta = (value/10000)&0xFF;
10961 seta = vbound(seta,-1,255);
10962 setb = vbound(setb,-1,255);
10963
10964 Awpn = seta;
10965 game->awpn = 255;
10966 game->forced_awpn = seta;
10967 game->items_off[seta] = 0;
10968 directItemA = seta;
10969
10970 Bwpn = setb;
10971 game->bwpn = 255;
10972 game->forced_bwpn = setb;
10973 game->items_off[setb] = 0;
10974 directItemB = setb;
10975 break;
10976 }
10977
10978
10979 case SETITEMSLOT:
10980 {
10981 //ri->d[rINDEX2] = 1st arg
10982 //ri->d[rINDEX] = 2nd arg
10983 //value = third arg
10984 //int32_t item, int32_t slot, int32_t force
10985 int32_t itm = ri->d[rINDEX]/10000;
10986 itm = vbound(itm, -1, 255);
10987
10988 int32_t slot = ri->d[rINDEX2]/10000;
10989 int32_t force = ri->d[rEXP1]/10000;
10990
10991 //If we add more item buttons, slot should be an int32_t
10992 //and force shuld be an int32_t
10993
10994 /*
10995 For zScript,
10996 const int32_t ITM_REQUIRE_NONE = 0
10997 const int32_t ITM_REQUIRE_INVENTORY = 1
10998 const int32_t ITM_REQUIRE_A_SLOT_RULE = 2
10999 //Combine as flags
11000 */
11001 if ( force == 0 )
11002 {
11003 switch(slot)
11004 {
11005 case 0: //b
11006 Bwpn = itm;
11007 game->items_off[itm] = 0;
11008 game->bwpn = 255;
11009 game->forced_bwpn = itm;
11010 directItemB = itm;
11011 break;
11012
11013 case 1: //a
11014 Awpn = itm;
11015 game->items_off[itm] = 0;
11016 game->awpn = 255;
11017 game->forced_awpn = itm;
11018 directItemA = itm;
11019 break;
11020
11021 case 2: //x
11022 Xwpn = itm;
11023 game->items_off[itm] = 0;
11024 game->xwpn = 255;
11025 game->forced_xwpn = itm;
11026 directItemX = itm;
11027 break;
11028
11029 case 3: //y
11030 Ywpn = itm;
11031 game->items_off[itm] = 0;
11032 game->ywpn = 255;
11033 game->forced_ywpn = itm;
11034 directItemX = itm;
11035 break;
11036 }
11037 }
11038 else if ( force == 1 )
11039 {
11040 if (game->item[itm])
11041 {
11042 switch(slot)
11043 {
11044 case 0: //b
11045 Bwpn = itm;
11046 game->items_off[itm] = 0;
11047 game->bwpn = 255;
11048 game->forced_bwpn = itm;
11049 directItemB = itm;
11050 break;
11051
11052 case 1: //a
11053 Awpn = itm;
11054 game->items_off[itm] = 0;
11055 game->awpn = 255;
11056 game->forced_awpn = itm;
11057 directItemA = itm;
11058 break;
11059
11060 case 2: //x
11061 Xwpn = itm;
11062 game->items_off[itm] = 0;
11063 game->xwpn = 255;
11064 game->forced_xwpn = itm;
11065 directItemX = itm;
11066 break;
11067
11068 case 3: //y
11069 Ywpn = itm;
11070 game->items_off[itm] = 0;
11071 game->ywpn = 255;
11072 game->forced_ywpn = itm;
11073 directItemY = itm;
11074 break;
11075 }
11076 }
11077 }
11078 else if ( force == 2 )
11079 {
11080 switch(slot)
11081 {
11082 case 0: //b
11083 Bwpn = itm;
11084 game->items_off[itm] = 0;
11085 game->bwpn = 255;
11086 game->forced_bwpn = itm;
11087 directItemB = itm;
11088 break;
11089
11090 case 1: //a
11091 if (get_qr(qr_SELECTAWPN))
11092 {
11093 Awpn = itm;
11094 game->items_off[itm] = 0;
11095 game->awpn = 255;
11096 game->forced_awpn = itm;
11097 directItemA = itm;
11098 }
11099 break;
11100
11101 case 2: //x
11102 Xwpn = itm;
11103 game->items_off[itm] = 0;
11104 game->xwpn = 255;
11105 game->forced_xwpn = itm;
11106 directItemX = itm;
11107 break;
11108
11109 case 3: //y
11110 Ywpn = itm;
11111 game->items_off[itm] = 0;
11112 game->ywpn = 255;
11113 game->forced_ywpn = itm;
11114 directItemY = itm;
11115 break;
11116 }
11117 }
11118 else if ( force == 3 ) //Flag ITM_REQUIRE_INVENTORY + ITM_REQUIRE_SLOT_A_RULE
11119 {
11120 if ( game->item[itm] )
11121 {
11122 switch(slot)
11123 {
11124 case 0: //b
11125 Bwpn = itm;
11126 game->items_off[itm] = 0;
11127 game->bwpn = 255;
11128 game->forced_bwpn = itm;
11129 directItemB = itm;
11130 break;
11131
11132 case 1: //a
11133 if (get_qr(qr_SELECTAWPN))
11134 {
11135 Awpn = itm;
11136 game->items_off[itm] = 0;
11137 game->awpn = 255;
11138 game->forced_awpn = itm;
11139 directItemA = itm;
11140 }
11141 break;
11142
11143 case 2: //x
11144 Xwpn = itm;
11145 game->items_off[itm] = 0;
11146 game->xwpn = 255;
11147 game->forced_xwpn = itm;
11148 directItemX = itm;
11149 break;
11150
11151 case 3: //y
11152 Ywpn = itm;
11153 game->items_off[itm] = 0;
11154 game->ywpn = 255;
11155 game->forced_ywpn = itm;
11156 directItemY = itm;
11157 break;
11158 }
11159 }
11160 }
11161 }
11162 break;
11163
11164 case LINKINVIS:
11165 837 Hero.setDontDraw((value ? 2 : 0));
11166 837 break;
11167
11168 case LINKINVINC:
11169 2288 Hero.scriptcoldet=(value/10000);
11170 2288 break;
11171
11172 case LINKENGINEANIMATE:
11173 Hero.do_animation=value;
11174 break;
11175
11176 case LINKSWORDJINX:
11177 718 Hero.setSwordClk(value/10000);
11178 718 break;
11179
11180 case LINKITEMJINX:
11181 5878 Hero.setItemClk(value/10000);
11182 5878 break;
11183
11184 case LINKDRUNK:
11185 1 Hero.setDrunkClock(value/10000);
11186 1 break;
11187
11188 case LINKHXOFS:
11189 (Hero.hxofs)=(zfix)(value/10000);
11190 break;
11191
11192 case LINKROTATION:
11193 if ( get_qr(qr_OLDSPRITEDRAWS) )
11194 {
11195 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
11196 break;
11197 }
11198 (Hero.rotation)=(value/10000);
11199 break;
11200
11201 case LINKSCALE:
11202 {
11203 if ( get_qr(qr_OLDSPRITEDRAWS) )
11204 {
11205 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
11206 break;
11207 }
11208 (Hero.scale)=(value/100.0);
11209 break;
11210 }
11211
11212 case LINKHYOFS:
11213 (Hero.hyofs)=(zfix)(value/10000);
11214 break;
11215
11216 case LINKXOFS:
11217 26326 (Hero.xofs)=(zfix)(value/10000);
11218 26326 break;
11219
11220 case LINKYOFS:
11221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388698 times.
388698 (Hero.yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
11222 388698 break;
11223 case HEROTOTALDYOFFS:
11224 break; //READ-ONLY
11225
11226 case HEROSHADOWXOFS:
11227 (Hero.shadowxofs)=(zfix)(value/10000);
11228 break;
11229
11230 case HEROSHADOWYOFS:
11231 (Hero.shadowyofs)=(zfix)(value/10000);
11232 break;
11233
11234 case LINKZOFS:
11235 (Hero.zofs)=(zfix)(value/10000);
11236 break;
11237
11238 case LINKHXSZ:
11239 (Hero.hit_width)=(zfix)(value/10000);
11240 break;
11241
11242 case LINKHYSZ:
11243 (Hero.hit_height)=(zfix)(value/10000);
11244 break;
11245
11246 case LINKHZSZ:
11247 (Hero.hzsz)=(zfix)(value/10000);
11248 break;
11249
11250 case LINKTXSZ:
11251 (Hero.txsz)=(zfix)(value/10000);
11252 break;
11253
11254 case LINKTYSZ:
11255 (Hero.tysz)=(zfix)(value/10000);
11256 break;
11257
11258 case LINKTILE:
11259 (Hero.tile)=(zfix)(value/10000);
11260 break;
11261
11262 case LINKFLIP:
11263 (Hero.flip)=(zfix)(value/10000);
11264 break;
11265
11266
11267
11268 case LINKINVFRAME:
11269 3 Hero.setHClk( (int32_t)vbound((value/10000), 0, 214747) );
11270 3 break;
11271
11272 case LINKCANFLICKER:
11273 277656 Hero.setCanFlicker((value/10000)?1:0);
11274 277656 break;
11275
11276 case LINKHURTSFX:
11277 277656 Hero.setHurtSFX( (int32_t)vbound((value/10000), 0, 255) );
11278 277656 break;
11279
11280
11281 case LINKITEMB:
11282 {
11283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 < -1 )
11284 {
11285 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
11286 break;
11287 }
11288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 > MAXITEMS-1 )
11289 {
11290 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
11291 break;
11292 }
11293 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11294
11295
2/2
✓ Branch 0 taken 93750 times.
✓ Branch 1 taken 9 times.
93759 if (Bwpn != (value/10000))
11296 {
11297 9 Bwpn = value/10000;
11298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(new_subscreen_active)
11299 9 new_subscreen_active->get_page_pos(Bwpn, game->bwpn);
11300 9 game->forced_bwpn = value/10000;
11301 9 game->items_off[value/10000] = 0;
11302 9 }
11303 93759 directItemB = value/10000;
11304 93759 break;
11305 }
11306
11307
11308 case LINKITEMA:
11309 {
11310
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 < -1 )
11311 {
11312 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
11313 break;
11314 }
11315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 > MAXITEMS-1 )
11316 {
11317 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
11318 break;
11319 }
11320 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11321
2/2
✓ Branch 0 taken 93752 times.
✓ Branch 1 taken 8 times.
93760 if (Awpn != (value/10000))
11322 {
11323 8 Awpn = value/10000;
11324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(new_subscreen_active)
11325 8 new_subscreen_active->get_page_pos(Awpn, game->awpn);
11326 8 game->items_off[value/10000] = 0;
11327 8 game->forced_awpn = value/10000;
11328 8 }
11329 93760 directItemA = value/10000;
11330 93760 break;
11331 }
11332
11333 case LINKITEMX:
11334 {
11335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 < -1 )
11336 {
11337 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
11338 break;
11339 }
11340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 > MAXITEMS-1 )
11341 {
11342 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
11343 break;
11344 }
11345 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11346
2/2
✓ Branch 0 taken 93739 times.
✓ Branch 1 taken 33 times.
93772 if (Xwpn != (value/10000))
11347 {
11348 33 Xwpn = value/10000;
11349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(new_subscreen_active)
11350 33 new_subscreen_active->get_page_pos(Xwpn, game->xwpn);
11351 33 game->items_off[value/10000] = 0;
11352 33 game->forced_xwpn = value/10000;
11353 33 }
11354 93772 directItemX = value/10000;
11355 93772 break;
11356 }
11357 case LINKITEMY:
11358 {
11359
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 < -1 )
11360 {
11361 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
11362 break;
11363 }
11364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 > MAXITEMS-1 )
11365 {
11366 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
11367 break;
11368 }
11369 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11370
2/2
✓ Branch 0 taken 93735 times.
✓ Branch 1 taken 43 times.
93778 if (Ywpn != (value/10000))
11371 {
11372 43 Ywpn = value/10000;
11373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(new_subscreen_active)
11374 43 new_subscreen_active->get_page_pos(Ywpn, game->ywpn);
11375 43 game->items_off[value/10000] = 0;
11376 43 game->forced_ywpn = value/10000;
11377 43 }
11378 93778 directItemY = value/10000;
11379 93778 break;
11380 }
11381
11382
11383 case LINKEATEN:
11384 Hero.setEaten(value/10000);
11385 break;
11386 case LINKGRABBED:
11387 Hero.inwallm = value != 0;
11388 break;
11389 case HEROBUNNY:
11390 Hero.setBunnyClock(value/10000);
11391 break;
11392 case LINKPUSH:
11393 Hero.pushing = zc_max((value/10000),0);
11394 break;
11395 case LINKSTUN:
11396 290 Hero.setStunClock(value/10000);
11397 290 break;
11398 case LINKSCRIPTTILE:
11399 4859 script_hero_sprite=vbound((value/10000), -1, NEWMAXTILES-1);
11400 4859 break;
11401
11402 case HEROSCRIPTCSET:
11403 3652 script_hero_cset=vbound((value/10000), -1, 0xF);
11404 3652 break;
11405 case LINKSCRIPFLIP:
11406 2578 script_hero_flip=vbound((value/10000),-1,256);
11407 2578 break;
11408
11409 case GAMESETA:
11410 {
11411 //int32_t state = (ri->d[rINDEX2]/10000);
11412 //int32_t extend = (ri->d[rINDEX2]/10000);
11413 //int32_t dir = (ri->d[rINDEX]/10000);
11414 // Z_message("Trying to force-set the A-button item().\n");
11415 // Hero.setAButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11416 }
11417 break;
11418
11419 case GAMESETB:
11420 {
11421 //int32_t state = (ri->d[rINDEX2]/10000);
11422 //int32_t extend = (ri->d[rINDEX2]/10000);
11423 //int32_t dir = (ri->d[rINDEX]/10000);
11424 // Z_message("Trying to force-set the A-button item().\n");
11425 // Hero.setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11426 }
11427 break;
11428
11429 //Set Hero Diagonal
11430 case LINKDIAG:
11431 Hero.setDiagMove(value?1:0);
11432 set_qr(qr_LTTPWALK, value?1:0);
11433 break;
11434
11435 //Set Hero Big Hitbox
11436 case LINKBIGHITBOX:
11437 Hero.setBigHitbox((value/10000)?1:0);
11438 set_qr(qr_LTTPCOLLISION, (value/10000)?1:0);
11439 break;
11440
11441 case LINKCLIMBING:
11442 Hero.setOnSideviewLadder(value!=0?true:false);
11443 break;
11444
11445 case HEROJUMPCOUNT:
11446 Hero.extra_jump_count = value/10000;
11447 break;
11448
11449 case HEROPULLCLK:
11450 Hero.pit_pullclk = value/10000;
11451 break;
11452 case HEROFALLCLK:
11453 {
11454 int32_t val = vbound(value/10000,0,70);
11455 if(val)
11456 Hero.setAction(falling);
11457 else if(Hero.action == falling)
11458 {
11459 Hero.setAction(none);
11460 }
11461 Hero.fallclk = val;
11462 break;
11463 }
11464 case HEROFALLCMB:
11465 Hero.fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
11466 break;
11467 case HERODROWNCLK:
11468 {
11469 int32_t val = vbound(value/10000,0,70);
11470 if(val)
11471 {
11472 if (Hero.action != lavadrowning) Hero.setAction(drowning);
11473 }
11474 else if(Hero.action == drowning || Hero.action == lavadrowning)
11475 {
11476 Hero.setAction(none);
11477 }
11478 Hero.drownclk = val;
11479 break;
11480 }
11481 case HERODROWNCMB:
11482 Hero.drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
11483 break;
11484 case HEROFAKEZ:
11485 {
11486 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
11487 {
11488 Hero.setFakeZfix(zslongToFix(value));
11489 }
11490 else
11491 {
11492 Hero.setFakeZ(value/10000);
11493 }
11494 }
11495 break;
11496
11497 case HEROSHIELDJINX:
11498 {
11499 Hero.shieldjinxclk = value / 10000;
11500 break;
11501 }
11502
11503 case CLOCKACTIVE:
11504 {
11505 4 Hero.setClock(watch=(value?true:false));
11506 4 break;
11507 }
11508
11509 case CLOCKCLK:
11510 clockclk = vbound((value/10000), 0, 214748);
11511 break;
11512
11513 case HERORESPAWNX:
11514 {
11515 zfix zx = zslongToFix(value);
11516 Hero.respawn_x = vbound(zx, 0_zf, 240_zf);
11517 break;
11518 }
11519
11520 case HERORESPAWNY:
11521 {
11522 zfix zy = zslongToFix(value);
11523 Hero.respawn_y = vbound(zy, 0_zf, 160_zf);
11524 break;
11525 }
11526
11527 case HERORESPAWNDMAP:
11528 {
11529 Hero.respawn_dmap = vbound(value/10000, 0, MAXDMAPS-1);
11530 break;
11531 }
11532
11533 case HERORESPAWNSCR:
11534 {
11535 Hero.respawn_scr = vbound(value/10000, 0, 0x7F);
11536 break;
11537 }
11538
11539
11540 case HEROSWITCHMAXTIMER:
11541 case HEROSWITCHTIMER:
11542 break; //read-only
11543
11544 case HEROIMMORTAL:
11545 {
11546 Hero.setImmortal(value/10000);
11547 break;
11548 }
11549
11550 case HEROCOYOTETIME:
11551 {
11552 auto v = value/10000;
11553 if(v < 0 || v > 65535) v = 65535;
11554 Hero.coyotetime = word(v);
11555 break;
11556 }
11557 case HEROLIFTEDWPN:
11558 {
11559 if(Hero.lift_wpn)
11560 {
11561 delete Hero.lift_wpn;
11562 Hero.lift_wpn = nullptr;
11563 }
11564 if(value)
11565 {
11566 if(weapon* wpn = checkLWpn(value))
11567 {
11568 if(wpn == Hero.lift_wpn) break;
11569 Hero.lift_wpn = wpn;
11570 if(Lwpns.find(wpn) > -1)
11571 Lwpns.remove(wpn);
11572 if(curScriptType == ScriptType::Lwpn && value == curScriptIndex)
11573 earlyretval = RUNSCRIPT_SELFREMOVE;
11574 }
11575 }
11576 break;
11577 }
11578 case HEROLIFTTIMER:
11579 {
11580 Hero.liftclk = value/10000;
11581 break;
11582 }
11583 case HEROLIFTMAXTIMER:
11584 {
11585 Hero.tliftclk = value/10000;
11586 break;
11587 }
11588 case HEROLIFTHEIGHT:
11589 {
11590 Hero.liftheight = zslongToFix(value);
11591 break;
11592 }
11593 case HEROHAMMERSTATE:
11594 {
11595 //readonly
11596 break;
11597 }
11598 case HEROFLICKERCOLOR:
11599 {
11600 Hero.flickercolor = value/10000;
11601 break;
11602 }
11603 case HEROFLICKERTRANSP:
11604 {
11605 Hero.flickertransp = value / 10000;
11606 break;
11607 }
11608 case HEROSCRICECMB:
11609 Hero.script_ice_combo = vbound(value/10000,-1,MAXCOMBOS); break;
11610 case HEROICEVX:
11611 Hero.ice_vx = zslongToFix(value); break;
11612 case HEROICEVY:
11613 Hero.ice_vy = zslongToFix(value); break;
11614 case HEROICEENTRYFRAMES:
11615 Hero.ice_entry_count = vbound(value/10000,0,255); break;
11616 case HEROICEENTRYMAXFRAMES:
11617 Hero.ice_entry_mcount = vbound(value/10000,0,255); break;
11618
11619
11620 ///----------------------------------------------------------------------------------------------------//
11621 //Input States
11622 case INPUTSTART:
11623 {
11624 1121819 control_state[6]=(value?true:false);
11625
2/2
✓ Branch 0 taken 1058724 times.
✓ Branch 1 taken 63095 times.
1121819 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[6]=false;
11626 1121819 break;
11627 }
11628
11629 case INPUTMAP:
11630 {
11631 646198 control_state[9]=(value?true:false);
11632
2/2
✓ Branch 0 taken 476961 times.
✓ Branch 1 taken 169237 times.
646198 if ( get_qr(qr_FIXDRUNKINPUTS) )
11633 169237 drunk_toggle_state[9]=false;
11634 646198 break;
11635 }
11636
11637 case INPUTUP:
11638 {
11639 298036 control_state[0]=(value?true:false);
11640
2/2
✓ Branch 0 taken 293445 times.
✓ Branch 1 taken 4591 times.
298036 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[0]=false;
11641 298036 break;
11642 }
11643
11644 case INPUTDOWN:
11645 {
11646 295303 control_state[1]=(value?true:false);
11647
2/2
✓ Branch 0 taken 290748 times.
✓ Branch 1 taken 4555 times.
295303 if ( get_qr(qr_FIXDRUNKINPUTS) )
11648 4555 drunk_toggle_state[1]=false;
11649 295303 break;
11650 }
11651
11652 case INPUTLEFT:
11653 {
11654 281941 control_state[2]=(value?true:false);
11655
2/2
✓ Branch 0 taken 277104 times.
✓ Branch 1 taken 4837 times.
281941 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[2]=false;
11656 281941 break;
11657 }
11658
11659 case INPUTRIGHT:
11660 {
11661 281894 control_state[3]=(value?true:false);
11662
2/2
✓ Branch 0 taken 277163 times.
✓ Branch 1 taken 4731 times.
281894 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[3]=false;
11663 281894 break;
11664 }
11665
11666 case INPUTA:
11667 {
11668 186826 control_state[4]=(value?true:false);
11669
2/2
✓ Branch 0 taken 142947 times.
✓ Branch 1 taken 43879 times.
186826 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[4]=false;
11670 186826 break;
11671 }
11672
11673 case INPUTB:
11674 {
11675 120700 control_state[5]=(value?true:false);
11676
2/2
✓ Branch 0 taken 116814 times.
✓ Branch 1 taken 3886 times.
120700 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[5]=false;
11677 120700 break;
11678 }
11679
11680 case INPUTL:
11681 {
11682 118163 control_state[7]=(value?true:false);
11683
2/2
✓ Branch 0 taken 116528 times.
✓ Branch 1 taken 1635 times.
118163 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[7]=false;
11684 118163 break;
11685 }
11686
11687 case INPUTR:
11688 {
11689 118214 control_state[8]=(value?true:false);
11690
2/2
✓ Branch 0 taken 116579 times.
✓ Branch 1 taken 1635 times.
118214 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[8]=false;
11691 118214 break;
11692 }
11693
11694 case INPUTEX1:
11695 {
11696 262073 control_state[10]=(value?true:false);
11697 262073 break;
11698 }
11699
11700 case INPUTEX2:
11701 262073 control_state[11]=(value?true:false);
11702 262073 break;
11703
11704 case INPUTEX3:
11705 262073 control_state[12]=(value?true:false);
11706 262073 break;
11707
11708 case INPUTEX4:
11709 262073 control_state[13]=(value?true:false);
11710 262073 break;
11711
11712 case INPUTAXISUP:
11713 control_state[14]=(value?true:false);
11714 break;
11715
11716 case INPUTAXISDOWN:
11717 control_state[15]=(value?true:false);
11718 break;
11719
11720 case INPUTAXISLEFT:
11721 control_state[16]=(value?true:false);
11722 break;
11723
11724 case INPUTAXISRIGHT:
11725 control_state[17]=(value?true:false);
11726 break;
11727
11728 case INPUTPRESSSTART:
11729 1121819 button_press[6]=(value?true:false);
11730 1121819 break;
11731
11732 case INPUTPRESSMAP:
11733 646198 button_press[9]=(value?true:false);
11734 646198 break;
11735
11736 case INPUTPRESSUP:
11737 261563 button_press[0]=(value?true:false);
11738 261563 break;
11739
11740 case INPUTPRESSDOWN:
11741 261555 button_press[1]=(value?true:false);
11742 261555 break;
11743
11744 case INPUTPRESSLEFT:
11745 261628 button_press[2]=(value?true:false);
11746 261628 break;
11747
11748 case INPUTPRESSRIGHT:
11749 261662 button_press[3]=(value?true:false);
11750 261662 break;
11751
11752 case INPUTPRESSA:
11753 177542 button_press[4]=(value?true:false);
11754 177542 break;
11755
11756 case INPUTPRESSB:
11757 111830 button_press[5]=(value?true:false);
11758 111830 break;
11759
11760 case INPUTPRESSL:
11761 115219 button_press[7]=(value?true:false);
11762 115219 break;
11763
11764 case INPUTPRESSR:
11765 115270 button_press[8]=(value?true:false);
11766 115270 break;
11767
11768 case INPUTPRESSEX1:
11769 262073 button_press[10]=(value?true:false);
11770 262073 break;
11771
11772 case INPUTPRESSEX2:
11773 262073 button_press[11]=(value?true:false);
11774 262073 break;
11775
11776 case INPUTPRESSEX3:
11777 262073 button_press[12]=(value?true:false);
11778 262073 break;
11779
11780 case INPUTPRESSEX4:
11781 262073 button_press[13]=(value?true:false);
11782 262073 break;
11783
11784 case PRESSAXISUP:
11785 button_press[14]=(value?true:false);
11786 break;
11787
11788 case PRESSAXISDOWN:
11789 button_press[15]=(value?true:false);
11790 break;
11791
11792 case PRESSAXISLEFT:
11793 button_press[16]=(value?true:false);
11794 break;
11795
11796 case PRESSAXISRIGHT:
11797 button_press[17]=(value?true:false);
11798 break;
11799
11800 case INPUTMOUSEX:
11801 {
11802 auto [x, y] = rti_game.local_to_world(value/10000, mouse_y);
11803 position_mouse(x, y);
11804 break;
11805 }
11806
11807 case INPUTMOUSEY:
11808 {
11809 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
11810 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
11811 auto [x, y] = rti_game.local_to_world(mouse_x, value/10000 + tempoffset);
11812 position_mouse(x, y);
11813 break;
11814 }
11815
11816 case INPUTMOUSEZ:
11817 position_mouse_z(value/10000);
11818 break;
11819
11820 case SIMULATEKEYPRESS:
11821 {
11822 //if ( !keypressed() ) break; //Don;t return values set by setting Hero->Input/Press
11823 //hmm...no, this won;t return properly for modifier keys.
11824 int32_t keyid = ri->d[rINDEX]/10000;
11825 //key = vbound(key,0,n);
11826 if (value/10000) simulate_keypress(keyid << 8);
11827 }
11828 break;
11829
11830 case KEYMODIFIERS:
11831 {
11832 key_shifts = ( value/10000 );
11833 break;
11834 }
11835 break;
11836
11837 ///----------------------------------------------------------------------------------------------------//
11838 //Itemdata Variables
11839 //not mine, but let;s guard some of them all the same -Z
11840 //item class
11841 case IDATAFAMILY:
11842 if(unsigned(ri->idata) >= MAXITEMS)
11843 {
11844 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11845 break;
11846 }
11847 (itemsbuf[ri->idata].family)=vbound(value/10000,0, 254);
11848 flushItemCache();
11849 break;
11850
11851 case IDATAUSEWPN:
11852 if(unsigned(ri->idata) >= MAXITEMS)
11853 {
11854 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11855 break;
11856 }
11857 (itemsbuf[ri->idata].weap_data.imitate_weapon)=vbound(value/10000, 0, 255);
11858 break;
11859 case IDATAUSEDEF:
11860 if(unsigned(ri->idata) >= MAXITEMS)
11861 {
11862 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11863 break;
11864 }
11865 (itemsbuf[ri->idata].weap_data.default_defense)=vbound(value/10000, 0, 255);
11866 break;
11867 case IDATAWRANGE:
11868 if(unsigned(ri->idata) >= MAXITEMS)
11869 {
11870 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11871 break;
11872 }
11873 (itemsbuf[ri->idata].weaprange)=vbound(value/10000, 0, 255);
11874 break;
11875 case IDATAMAGICTIMER:
11876 if(unsigned(ri->idata) >= MAXITEMS)
11877 {
11878 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11879 break;
11880 }
11881 (itemsbuf[ri->idata].magiccosttimer[0])=vbound(value/10000, 0, 214747);
11882 break;
11883 case IDATAMAGICTIMER2:
11884 if(unsigned(ri->idata) >= MAXITEMS)
11885 {
11886 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11887 break;
11888 }
11889 (itemsbuf[ri->idata].magiccosttimer[1])=vbound(value/10000, 0, 214747);
11890 break;
11891 case IDATADURATION:
11892 if(unsigned(ri->idata) >= MAXITEMS)
11893 {
11894 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11895 break;
11896 }
11897 (itemsbuf[ri->idata].weapduration)=vbound(value/10000, 0, 255);
11898 break;
11899
11900 case IDATADUPLICATES:
11901 if(unsigned(ri->idata) >= MAXITEMS)
11902 {
11903 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11904 break;
11905 }
11906 (itemsbuf[ri->idata].duplicates)=vbound(value/10000, 0, 255);
11907 break;
11908 case IDATADRAWLAYER:
11909 if(unsigned(ri->idata) >= MAXITEMS)
11910 {
11911 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11912 break;
11913 }
11914 (itemsbuf[ri->idata].drawlayer)=vbound(value/10000, 0, 7);
11915 break;
11916 case IDATACOLLECTFLAGS:
11917 if(unsigned(ri->idata) >= MAXITEMS)
11918 {
11919 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11920 break;
11921 }
11922 //int32_t a = ri->d[rINDEX] / 10000;
11923 (itemsbuf[ri->idata].collectflags)=vbound(value/10000, 0, 214747);
11924 break;
11925 case IDATAWEAPONSCRIPT:
11926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(unsigned(ri->idata) >= MAXITEMS)
11927 {
11928 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11929 break;
11930 }
11931 2 (itemsbuf[ri->idata].weap_data.script)=vbound(value/10000, 0, 255);
11932 2 break;
11933 case IDATAWEAPHXOFS:
11934 if(unsigned(ri->idata) >= MAXITEMS)
11935 {
11936 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11937 break;
11938 }
11939 (itemsbuf[ri->idata].weap_data.hxofs)=(value/10000);
11940 break;
11941 case IDATAWEAPHYOFS:
11942 if(unsigned(ri->idata) >= MAXITEMS)
11943 {
11944 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11945 break;
11946 }
11947 (itemsbuf[ri->idata].weap_data.hyofs)=(value/10000);
11948 break;
11949 case IDATAWEAPHXSZ:
11950 if(unsigned(ri->idata) >= MAXITEMS)
11951 {
11952 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11953 break;
11954 }
11955 (itemsbuf[ri->idata].weap_data.hxsz)=(value/10000);
11956 break;
11957 case IDATAWEAPHYSZ:
11958 if(unsigned(ri->idata) >= MAXITEMS)
11959 {
11960 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11961 break;
11962 }
11963 (itemsbuf[ri->idata].weap_data.hysz)=(value/10000);
11964 break;
11965 case IDATAWEAPHZSZ:
11966 if(unsigned(ri->idata) >= MAXITEMS)
11967 {
11968 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11969 break;
11970 }
11971 (itemsbuf[ri->idata].weap_data.hzsz)=(value/10000);
11972 break;
11973 case IDATAWEAPXOFS:
11974 if(unsigned(ri->idata) >= MAXITEMS)
11975 {
11976 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11977 break;
11978 }
11979 (itemsbuf[ri->idata].weap_data.xofs)=(value/10000);
11980 break;
11981 case IDATAWEAPYOFS:
11982 if(unsigned(ri->idata) >= MAXITEMS)
11983 {
11984 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11985 break;
11986 }
11987 (itemsbuf[ri->idata].weap_data.yofs)=(value/10000);
11988 break;
11989
11990
11991 case IDATAHXOFS:
11992 if(unsigned(ri->idata) >= MAXITEMS)
11993 {
11994 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11995 break;
11996 }
11997 (itemsbuf[ri->idata].hxofs)=(value/10000);
11998 break;
11999 case IDATAHYOFS:
12000 if(unsigned(ri->idata) >= MAXITEMS)
12001 {
12002 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12003 break;
12004 }
12005 (itemsbuf[ri->idata].hyofs)=(value/10000);
12006 break;
12007 case IDATAHXSZ:
12008 if(unsigned(ri->idata) >= MAXITEMS)
12009 {
12010 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12011 break;
12012 }
12013 (itemsbuf[ri->idata].hxsz)=(value/10000);
12014 break;
12015 case IDATAHYSZ:
12016 if(unsigned(ri->idata) >= MAXITEMS)
12017 {
12018 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12019 break;
12020 }
12021 (itemsbuf[ri->idata].hysz)=(value/10000);
12022 break;
12023 case IDATAHZSZ:
12024 if(unsigned(ri->idata) >= MAXITEMS)
12025 {
12026 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12027 break;
12028 }
12029 (itemsbuf[ri->idata].hzsz)=(value/10000);
12030 break;
12031 case IDATADXOFS:
12032 if(unsigned(ri->idata) >= MAXITEMS)
12033 {
12034 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12035 break;
12036 }
12037 (itemsbuf[ri->idata].xofs)=(value/10000);
12038 break;
12039 case IDATADYOFS:
12040 if(unsigned(ri->idata) >= MAXITEMS)
12041 {
12042 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12043 break;
12044 }
12045 (itemsbuf[ri->idata].yofs)=(value/10000);
12046 break;
12047 case IDATATILEW:
12048 if(unsigned(ri->idata) >= MAXITEMS)
12049 {
12050 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12051 break;
12052 }
12053 (itemsbuf[ri->idata].tilew)=(value/10000);
12054 break;
12055 case IDATATILEH:
12056 if(unsigned(ri->idata) >= MAXITEMS)
12057 {
12058 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12059 break;
12060 }
12061 (itemsbuf[ri->idata].tileh)=(value/10000);
12062 break;
12063 case IDATAPICKUP:
12064 if(unsigned(ri->idata) >= MAXITEMS)
12065 {
12066 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12067 break;
12068 }
12069 (itemsbuf[ri->idata].pickup)=(value/10000);
12070 break;
12071 case IDATAOVERRIDEFL:
12072 if(unsigned(ri->idata) >= MAXITEMS)
12073 {
12074 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12075 break;
12076 }
12077 (itemsbuf[ri->idata].overrideFLAGS)=(value/10000);
12078 break;
12079
12080 case IDATATILEWWEAP:
12081 if(unsigned(ri->idata) >= MAXITEMS)
12082 {
12083 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12084 break;
12085 }
12086 (itemsbuf[ri->idata].weap_data.tilew)=(value/10000);
12087 break;
12088 case IDATATILEHWEAP:
12089 if(unsigned(ri->idata) >= MAXITEMS)
12090 {
12091 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12092 break;
12093 }
12094 (itemsbuf[ri->idata].weap_data.tileh)=(value/10000);
12095 break;
12096 case IDATAOVERRIDEFLWEAP:
12097 if(unsigned(ri->idata) >= MAXITEMS)
12098 {
12099 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12100 break;
12101 }
12102 (itemsbuf[ri->idata].weap_data.override_flags)=(value/10000);
12103 break;
12104
12105 case IDATAUSEMVT:
12106 {
12107 if(unsigned(ri->idata) >= MAXITEMS)
12108 {
12109 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12110 break;
12111 }
12112 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
12113 (itemsbuf[ri->idata].weap_pattern[a])=vbound(value/10000, 0, 255);
12114 break;
12115 }
12116
12117 case IDATALEVEL:
12118 if(unsigned(ri->idata) >= MAXITEMS)
12119 {
12120 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12121 break;
12122 }
12123 (itemsbuf[ri->idata].fam_type)=vbound(value/10000, 0, 512);
12124 flushItemCache();
12125 break;
12126 case IDATAKEEP:
12127 item_flag(item_gamedata, value);
12128 break;
12129 case IDATAAMOUNT:
12130 {
12131 if(unsigned(ri->idata) >= MAXITEMS)
12132 {
12133 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12134 break;
12135 }
12136 int32_t v = vbound(value/10000, -9999, 16383);
12137 itemsbuf[ri->idata].amount &= 0x8000;
12138 itemsbuf[ri->idata].amount |= (abs(v)&0x3FFF)|(v<0?0x4000:0);
12139 break;
12140 }
12141 case IDATAGRADUAL:
12142 {
12143 if(unsigned(ri->idata) >= MAXITEMS)
12144 {
12145 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12146 break;
12147 }
12148 SETFLAG(itemsbuf[ri->idata].amount, 0x8000, value!=0);
12149 break;
12150 }
12151 case IDATACONSTSCRIPT:
12152 item_flag(item_passive_script, value);
12153 break;
12154 case IDATASSWIMDISABLED:
12155 item_flag(item_sideswim_disabled, value);
12156 break;
12157 case IDATABUNNYABLE:
12158 item_flag(item_bunny_enabled, value);
12159 break;
12160 case IDATAJINXIMMUNE:
12161 item_flag(item_jinx_immune, value);
12162 break;
12163 case IDATAJINXSWAP:
12164 item_flag(item_flip_jinx, value);
12165 break;
12166 case IDATAUSEBURNSPR:
12167 if(unsigned(ri->idata) >= MAXITEMS)
12168 {
12169 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12170 }
12171 else SETFLAG(itemsbuf[ri->idata].weap_data.wflags, WFLAG_UPDATE_IGNITE_SPRITE, value);
12172 break;
12173 case IDATASETMAX:
12174 if(unsigned(ri->idata) >= MAXITEMS)
12175 {
12176 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12177 break;
12178 }
12179 (itemsbuf[ri->idata].setmax)=value/10000;
12180 break;
12181
12182 case IDATAMAX:
12183 if(unsigned(ri->idata) >= MAXITEMS)
12184 {
12185 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12186 break;
12187 }
12188 (itemsbuf[ri->idata].max)=value/10000;
12189 break;
12190
12191 case IDATAPOWER:
12192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
182 if(unsigned(ri->idata) >= MAXITEMS)
12193 {
12194 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12195 break;
12196 }
12197 182 (itemsbuf[ri->idata].power)=value/10000;
12198 182 break;
12199
12200 case IDATACOUNTER:
12201 if(unsigned(ri->idata) >= MAXITEMS)
12202 {
12203 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12204 break;
12205 }
12206 (itemsbuf[ri->idata].count)=vbound(value/10000,0,31);
12207 break;
12208
12209 case IDATAPSOUND:
12210 if(unsigned(ri->idata) >= MAXITEMS)
12211 {
12212 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12213 break;
12214 }
12215 (itemsbuf[ri->idata].playsound)=vbound(value/10000, 0, 255);
12216 break;
12217
12218 case IDATAUSESOUND:
12219 if(unsigned(ri->idata) >= MAXITEMS)
12220 {
12221 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12222 break;
12223 }
12224 (itemsbuf[ri->idata].usesound)=vbound(value/10000, 0, 255);
12225 break;
12226
12227 case IDATAUSESOUND2:
12228 if(unsigned(ri->idata) >= MAXITEMS)
12229 {
12230 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12231 break;
12232 }
12233 (itemsbuf[ri->idata].usesound2)=vbound(value/10000, 0, 255);
12234 break;
12235
12236 //2.54
12237 //My additions begin here. -Z
12238 //Stack item to gain next level
12239 case IDATACOMBINE:
12240 item_flag(item_combine, value);
12241 break;
12242 //using a level of an item downgrades to a lower one
12243 case IDATADOWNGRADE:
12244 item_flag(item_downgrade, value);
12245 break;
12246 //Only validate the cost, don't charge it
12247 case IDATAVALIDATE:
12248 item_flag(item_validate_only, value);
12249 break;
12250 case IDATAVALIDATE2:
12251 item_flag(item_validate_only_2, value);
12252 break;
12253
12254
12255 //Keep Old in editor
12256 case IDATAKEEPOLD:
12257 item_flag(item_keep_old, value);
12258 break;
12259 //Ruppes for magic
12260 case IDATARUPEECOST:
12261 item_flag(item_rupee_magic, value);
12262 break;
12263 //can be eaten
12264 case IDATAEDIBLE:
12265 item_flag(item_edible, value);
12266 break;
12267 //Unused at this time
12268 case IDATAFLAGUNUSED:
12269 item_flag(item_unused, value);
12270 break;
12271 //gain lower level items
12272 case IDATAGAINLOWER:
12273 item_flag(item_gain_old, value);
12274 break;
12275 //Set the action script
12276 case IDATASCRIPT:
12277 if(unsigned(ri->idata) >= MAXITEMS)
12278 {
12279 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12280 break;
12281 }
12282 FFScript::deallocateAllScriptOwned(ScriptType::Item, ri->idata);
12283 itemsbuf[ri->idata].script=vbound(value/10000,0,255);
12284 break;
12285 case IDATASPRSCRIPT:
12286 if(unsigned(ri->idata) >= MAXITEMS)
12287 {
12288 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12289 break;
12290 }
12291 itemsbuf[ri->idata].sprite_script=vbound(value/10000,0,255);
12292 break;
12293
12294 //Hero tile modifier.
12295 case IDATALTM:
12296 {
12297 if(unsigned(ri->idata) >= MAXITEMS)
12298 {
12299 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12300 break;
12301 }
12302 auto new_value = value/10000;
12303 if (new_value != itemsbuf[ri->idata].ltm)
12304 cache_tile_mod_clear();
12305 itemsbuf[ri->idata].ltm = new_value;
12306 break;
12307 }
12308 //Pickup script
12309 case IDATAPSCRIPT:
12310 {
12311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2760 times.
2760 if(unsigned(ri->idata) >= MAXITEMS)
12312 {
12313 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12314 break;
12315 }
12316 //Need to get collect script ref, not standard idata ref!
12317
1/2
✓ Branch 0 taken 2760 times.
✗ Branch 1 not taken.
2760 const int32_t new_ref = ri->idata!=0 ? -(ri->idata) : COLLECT_SCRIPT_ITEM_ZERO;
12318 2760 FFScript::deallocateAllScriptOwned(ScriptType::Item,new_ref);
12319 2760 itemsbuf[ri->idata].collect_script=vbound(value/10000, 0, 255);
12320 2760 break;
12321 }
12322 //pickup string
12323 case IDATAPSTRING:
12324 if(unsigned(ri->idata) >= MAXITEMS)
12325 {
12326 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12327 break;
12328 }
12329 itemsbuf[ri->idata].pstring=vbound(value/10000, 1, 255);
12330 break;
12331 case IDATAPFLAGS:
12332 if(unsigned(ri->idata) >= MAXITEMS)
12333 {
12334 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12335 break;
12336 }
12337 itemsbuf[ri->idata].pickup_string_flags=vbound(value/10000, 0, 214748);
12338 break;
12339 case IDATAPICKUPLITEMS:
12340 if(unsigned(ri->idata) >= MAXITEMS)
12341 {
12342 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12343 break;
12344 }
12345 itemsbuf[ri->idata].pickup_litems = vbound(value/10000, 0, 214748) & liALL;
12346 break;
12347 case IDATAPICKUPLITEMLEVEL:
12348 if(unsigned(ri->idata) >= MAXITEMS)
12349 {
12350 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12351 break;
12352 }
12353 itemsbuf[ri->idata].pickup_litem_level = vbound(value/10000, -1, MAXLEVELS-1);
12354 break;
12355 //magic cost
12356 case IDATAMAGCOST:
12357 if(unsigned(ri->idata) >= MAXITEMS)
12358 {
12359 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12360 break;
12361 }
12362 itemsbuf[ri->idata].cost_amount[0]=vbound(value/10000,32767,-32768);
12363 break;
12364 case IDATACOST2:
12365 if(unsigned(ri->idata) >= MAXITEMS)
12366 {
12367 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12368 break;
12369 }
12370 itemsbuf[ri->idata].cost_amount[1]=vbound(value/10000,32767,-32768);
12371 break;
12372 //cost counter ref
12373 case IDATACOSTCOUNTER:
12374 if(unsigned(ri->idata) >= MAXITEMS)
12375 {
12376 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12377 break;
12378 }
12379 itemsbuf[ri->idata].cost_counter[0]=(vbound(value/10000,-1,32));
12380 break;
12381 case IDATACOSTCOUNTER2:
12382 if(unsigned(ri->idata) >= MAXITEMS)
12383 {
12384 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12385 break;
12386 }
12387 itemsbuf[ri->idata].cost_counter[1]=(vbound(value/10000,-1,32));
12388 break;
12389 //min hearts to pick up
12390 case IDATAMINHEARTS:
12391 if(unsigned(ri->idata) >= MAXITEMS)
12392 {
12393 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12394 break;
12395 }
12396 itemsbuf[ri->idata].pickup_hearts=vbound(value/10000, 0, 214748);
12397 break;
12398 //item tile
12399 case IDATATILE:
12400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if(unsigned(ri->idata) >= MAXITEMS)
12401 {
12402 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12403 break;
12404 }
12405 94 itemsbuf[ri->idata].tile=vbound(value/10000, 0, NEWMAXTILES-1);
12406 94 break;
12407 //flash
12408 case IDATAMISC:
12409 if(unsigned(ri->idata) >= MAXITEMS)
12410 {
12411 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12412 break;
12413 }
12414 itemsbuf[ri->idata].misc_flags=value/10000;
12415 break;
12416 //cset
12417 case IDATACSET:
12418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(unsigned(ri->idata) >= MAXITEMS)
12419 {
12420 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12421 break;
12422 }
12423
12424 13 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
12425
12426 // If we find quests that broke, use this code.
12427 // if (QHeader.compareVer(2, 55, 9) >= 0)
12428 // itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
12429 // else
12430 // itemsbuf[ri->idata].csets = vbound(value/10000,0,13);
12431 13 break;
12432
12433 case IDATAFLASHCSET:
12434 if(unsigned(ri->idata) >= MAXITEMS)
12435 {
12436 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12437 break;
12438 }
12439
12440 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF) | (vbound(value/10000,0,15)<<4);
12441 break;
12442 /*
12443 case IDATAFRAME:
12444 itemsbuf[ri->idata].frame=value/10000;
12445 break;
12446 */
12447 //A.Frames
12448 case IDATAFRAMES:
12449 if(unsigned(ri->idata) >= MAXITEMS)
12450 {
12451 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12452 break;
12453 }
12454 (itemsbuf[ri->idata].frames)=vbound(value/10000, 0, 214748);
12455 break;
12456 //A.speed
12457 case IDATAASPEED:
12458 if(unsigned(ri->idata) >= MAXITEMS)
12459 {
12460 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12461 break;
12462 }
12463 itemsbuf[ri->idata].speed=vbound(value/10000, 0, 214748);
12464 break;
12465 //Anim delay
12466 case IDATADELAY:
12467 if(unsigned(ri->idata) >= MAXITEMS)
12468 {
12469 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12470 break;
12471 }
12472 itemsbuf[ri->idata].delay=vbound(value/10000, 0, 214748);
12473 break;
12474
12475 ///----------------------------------------------------------------------------------------------------//
12476 //LWeapon Variables
12477
12478 case LWPNSCALE:
12479 if ( get_qr(qr_OLDSPRITEDRAWS) )
12480 {
12481 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
12482 break;
12483 }
12484 if(0!=(s=checkLWpn(ri->lwpn)))
12485 ((weapon*)s)->scale=(zfix)(value/100.0);
12486
12487 break;
12488
12489 case LWPNX:
12490
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207340 times.
214057 if(0!=(s=checkLWpn(ri->lwpn)))
12491
2/2
✓ Branch 0 taken 67473 times.
✓ Branch 1 taken 139867 times.
207340 ((weapon*)s)->x=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12492 214057 break;
12493
12494 case SPRITEMAXLWPN:
12495 {
12496 //No bounds check, as this is a universal function and works from NULL pointers!
12497 1 Lwpns.setMax(vbound((value/10000),1,MAX_LWPN_SPRITES));
12498 1 break;
12499 }
12500
12501 case LWPNY:
12502
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207326 times.
214043 if(0!=(s=checkLWpn(ri->lwpn)))
12503
2/2
✓ Branch 0 taken 67466 times.
✓ Branch 1 taken 139860 times.
207326 ((weapon*)s)->y=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12504
12505 214043 break;
12506
12507 case LWPNZ:
12508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 971 times.
971 if(0!=(s=checkLWpn(ri->lwpn)))
12509 {
12510
2/2
✓ Branch 0 taken 965 times.
✓ Branch 1 taken 6 times.
971 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12511
1/2
✓ Branch 0 taken 971 times.
✗ Branch 1 not taken.
971 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
12512 971 }
12513
12514 971 break;
12515
12516 case LWPNJUMP:
12517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if(0!=(s=checkLWpn(ri->lwpn)))
12518 408 ((weapon*)s)->fall=zslongToFix(value)*-100;
12519
12520 408 break;
12521
12522 case LWPNFAKEJUMP:
12523 if(0!=(s=checkLWpn(ri->lwpn)))
12524 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
12525
12526 break;
12527
12528 case LWPNDIR:
12529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71609 times.
71609 if(0!=(s=checkLWpn(ri->lwpn)))
12530 {
12531 71609 ((weapon*)s)->dir=(value/10000);
12532 71609 ((weapon*)s)->doAutoRotate(true);
12533 71609 }
12534
12535 71609 break;
12536
12537 case LWPNSPECIAL:
12538 if(0!=(s=checkLWpn(ri->lwpn)))
12539 ((weapon*)s)->specialinfo=(value/10000);
12540
12541 break;
12542
12543 case LWPNGRAVITY:
12544 if(0!=(s=checkLWpn(ri->lwpn)))
12545 {
12546 if(value)
12547 ((weapon*)s)->moveflags |= move_obeys_grav;
12548 else
12549 ((weapon*)s)->moveflags &= ~move_obeys_grav;
12550 }
12551 break;
12552
12553 case LWPNSTEP:
12554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if(0!=(s=checkLWpn(ri->lwpn)))
12555 {
12556 // fp math is bad for replay, so always ignore this QR when replay is active.
12557 // TODO: can we just delete this QR? Would it actually break anything? For now,
12558 // just disable for replay and wait for more tests to be played with this QR
12559 // ignored.
12560
3/4
✓ Branch 0 taken 7619 times.
✓ Branch 1 taken 2167 times.
✓ Branch 2 taken 7619 times.
✗ Branch 3 not taken.
9786 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
12561 {
12562 9786 ((weapon*)s)->step= zslongToFix(value / 100);
12563 9786 }
12564 else
12565 {
12566 //old, buggy code replication, round two: Go! -Z
12567 //zfix val = zslongToFix(value);
12568 //val.doFloor();
12569 //((weapon*)s)->step = ((val / 100.0).getFloat());
12570
12571 //old, buggy code replication, round THREE: Go! -Z
12572 ((weapon*)s)->step = ((value/10000)/100.0);
12573 }
12574
12575 9786 }
12576
12577 9786 break;
12578
12579 case LWPNANGLE:
12580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1679 times.
1679 if(0!=(s=checkLWpn(ri->lwpn)))
12581 {
12582 1679 ((weapon*)s)->angle=(double)(value/10000.0);
12583 1679 ((weapon*)(s))->doAutoRotate();
12584 1679 }
12585
12586 1679 break;
12587
12588 case LWPNDEGANGLE:
12589 if(0!=(s=checkLWpn(ri->lwpn)))
12590 {
12591 double rangle = (value / 10000.0) * (PI / 180.0);
12592 ((weapon*)s)->angle=(double)(rangle);
12593 ((weapon*)(s))->doAutoRotate();
12594 }
12595
12596 break;
12597
12598 case LWPNVX:
12599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12600 {
12601 double vy;
12602 6 double vx = (value / 10000.0);
12603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (((weapon*)(s))->angular)
12604 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
12605 else
12606 {
12607
5/7
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
6 switch(NORMAL_DIR(((weapon*)(s))->dir))
12608 {
12609 case l_up:
12610 case r_up:
12611 case up:
12612 2 vy = -1.0*((weapon*)s)->step;
12613 2 break;
12614 case l_down:
12615 case r_down:
12616 case down:
12617 2 vy = ((weapon*)s)->step;
12618 2 break;
12619
12620 default:
12621 2 vy = 0;
12622 2 break;
12623 }
12624 }
12625 6 ((weapon*)s)->angular = true;
12626 6 ((weapon*)s)->angle=atan2(vy, vx);
12627 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
12628 6 ((weapon*)(s))->doAutoRotate();
12629 6 }
12630
12631 6 break;
12632
12633 case LWPNVY:
12634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12635 {
12636 double vx;
12637 6 double vy = (value / 10000.0);
12638
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (((weapon*)(s))->angular)
12639 6 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
12640 else
12641 {
12642 switch(NORMAL_DIR(((weapon*)(s))->dir))
12643 {
12644 case l_up:
12645 case l_down:
12646 case left:
12647 vx = -1.0*((weapon*)s)->step;
12648 break;
12649 case r_down:
12650 case r_up:
12651 case right:
12652 vx = ((weapon*)s)->step;
12653 break;
12654
12655 default:
12656 vx = 0;
12657 break;
12658 }
12659 }
12660 6 ((weapon*)s)->angular = true;
12661 6 ((weapon*)s)->angle=atan2(vy, vx);
12662 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
12663 6 ((weapon*)(s))->doAutoRotate();
12664 6 }
12665
12666 6 break;
12667
12668 case LWPNANGULAR:
12669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1181 times.
1181 if(0!=(s=checkLWpn(ri->lwpn)))
12670 {
12671 1181 ((weapon*)s)->angular=(value!=0);
12672 1181 ((weapon*)(s))->doAutoRotate(false, true);
12673 1181 }
12674
12675 1181 break;
12676
12677 case LWPNAUTOROTATE:
12678 if(0!=(s=checkLWpn(ri->lwpn)))
12679 {
12680 ((weapon*)s)->autorotate=(value!=0);
12681 ((weapon*)(s))->doAutoRotate(false, true);
12682 }
12683
12684 break;
12685
12686 case LWPNBEHIND:
12687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if(0!=(s=checkLWpn(ri->lwpn)))
12688 1131 ((weapon*)s)->behind=(value!=0);
12689
12690 1131 break;
12691
12692 case LWPNDRAWTYPE:
12693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 476 times.
476 if(0!=(s=checkLWpn(ri->lwpn)))
12694 476 ((weapon*)s)->drawstyle=(value/10000);
12695
12696 476 break;
12697
12698 case LWPNPOWER:
12699
1/2
✓ Branch 0 taken 76041 times.
✗ Branch 1 not taken.
76041 if(0!=(s=checkLWpn(ri->lwpn)))
12700 76041 ((weapon*)s)->power=(value/10000);
12701
12702 76041 break;
12703 /*
12704 case LWPNRANGE:
12705 if(0!=(s=checkLWpn(ri->lwpn)))
12706 ((weapon*)s)->scriptrange=vbound((value/10000),0,512); //Allow it to move off-screen. -Z
12707 break;
12708 */
12709 case LWPNDEAD:
12710
2/2
✓ Branch 0 taken 147078 times.
✓ Branch 1 taken 6717 times.
153795 if(0!=(s=checkLWpn(ri->lwpn)))
12711 {
12712 147078 auto dead = value/10000;
12713 147078 ((weapon*)s)->dead=dead;
12714
2/2
✓ Branch 0 taken 74907 times.
✓ Branch 1 taken 72171 times.
147078 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
12715 147078 }
12716 153795 break;
12717
12718 case LWPNID:
12719 if(0!=(s=checkLWpn(ri->lwpn)))
12720 ((weapon*)s)->id=(value/10000);
12721
12722 break;
12723
12724 case LWPNTILE:
12725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2464 times.
2464 if(0!=(s=checkLWpn(ri->lwpn)))
12726 2464 ((weapon*)s)->tile=(value/10000);
12727
12728 2464 break;
12729
12730 case LWPNSCRIPTTILE:
12731
1/2
✓ Branch 0 taken 3263 times.
✗ Branch 1 not taken.
3263 if(0!=(s=checkLWpn(ri->lwpn)))
12732 3263 ((weapon*)s)->scripttile=vbound((value/10000),-1,NEWMAXTILES-1);
12733
12734 3263 break;
12735
12736 case LWPNSCRIPTFLIP:
12737 if(0!=(s=checkLWpn(ri->lwpn)))
12738 ((weapon*)s)->scriptflip=vbound((value/10000),-1,127);
12739
12740 break;
12741
12742 case LWPNCSET:
12743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26540 times.
26540 if(0!=(s=checkLWpn(ri->lwpn)))
12744 26540 ((weapon*)s)->cs=(value/10000)&15;
12745
12746 26540 break;
12747
12748 case LWPNFLASHCSET:
12749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12750 6 (((weapon*)s)->o_cset)|=(value/10000)<<4;
12751
12752 6 break;
12753
12754 case LWPNFRAMES:
12755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 429 times.
429 if(0!=(s=checkLWpn(ri->lwpn)))
12756 429 ((weapon*)s)->frames=(value/10000);
12757
12758 429 break;
12759
12760 case LWPNFRAME:
12761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12762 6 ((weapon*)s)->aframe=(value/10000);
12763
12764 6 break;
12765
12766 case LWPNASPEED:
12767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527 times.
527 if(0!=(s=checkLWpn(ri->lwpn)))
12768 527 ((weapon*)s)->o_speed=(value/10000);
12769
12770 527 break;
12771
12772 case LWPNFLASH:
12773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12774 6 ((weapon*)s)->flash=(value/10000);
12775
12776 6 break;
12777
12778 case LWPNFLIP:
12779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 885 times.
885 if(0!=(s=checkLWpn(ri->lwpn)))
12780 885 ((weapon*)s)->flip=(value/10000);
12781
12782 885 break;
12783
12784 case LWPNROTATION:
12785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if ( get_qr(qr_OLDSPRITEDRAWS) )
12786 {
12787 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
12788 break;
12789 }
12790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if(0!=(s=checkLWpn(ri->lwpn)))
12791 4922 ((weapon*)s)->rotation=(value/10000);
12792
12793 4922 break;
12794
12795 case LWPNEXTEND:
12796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 839 times.
839 if(0!=(s=checkLWpn(ri->lwpn)))
12797 839 ((weapon*)s)->extend=(value/10000);
12798
12799 839 break;
12800
12801 case LWPNOTILE:
12802
1/2
✓ Branch 0 taken 2345 times.
✗ Branch 1 not taken.
2345 if(0!=(s=checkLWpn(ri->lwpn)))
12803 {
12804 2345 ((weapon*)s)->o_tile=(value/10000);
12805 2345 ((weapon*)s)->ref_o_tile=(value/10000);
12806 //((weapon*)s)->script_wrote_otile=1; //Removing this as of 26th October, 2019 -Z
12807 //if at some future point we WANT writing ->Tile to also overwrite ->OriginalTile,
12808 //then either the user will need to manually write tile, or we can add a QR and
12809 // write ->tile here. 'script_wrote_otile' is out.
12810 2345 }
12811 2345 break;
12812
12813 case LWPNOCSET:
12814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12815 6 (((weapon*)s)->o_cset)|=(value/10000)&15;
12816
12817 6 break;
12818
12819 case LWPNHXOFS:
12820
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71310 times.
71310 if(0!=(s=checkLWpn(ri->lwpn)))
12821 71310 (((weapon*)s)->hxofs)=(value/10000);
12822
12823 71310 break;
12824
12825 case LWPNHYOFS:
12826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71308 times.
71308 if(0!=(s=checkLWpn(ri->lwpn)))
12827 71308 (((weapon*)s)->hyofs)=(value/10000);
12828
12829 71308 break;
12830
12831 case LWPNXOFS:
12832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1768 times.
1768 if(0!=(s=checkLWpn(ri->lwpn)))
12833 1768 (((weapon*)s)->xofs)=(zfix)(value/10000);
12834
12835 1768 break;
12836
12837 case LWPNYOFS:
12838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 if(0!=(s=checkLWpn(ri->lwpn)))
12839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
12840
12841 70954 break;
12842
12843 case LWPNSHADOWXOFS:
12844 if(0!=(s=checkLWpn(ri->lwpn)))
12845 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
12846
12847 break;
12848
12849 case LWPNSHADOWYOFS:
12850 if(0!=(s=checkLWpn(ri->lwpn)))
12851 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
12852
12853 break;
12854
12855 case LWPNTOTALDYOFFS:
12856 break; //READ-ONLY
12857
12858 case LWPNZOFS:
12859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12860 6 (((weapon*)s)->zofs)=(zfix)(value/10000);
12861
12862 6 break;
12863
12864 case LWPNHXSZ:
12865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72525 times.
72525 if(0!=(s=checkLWpn(ri->lwpn)))
12866 72525 (((weapon*)s)->hit_width)=(value/10000);
12867
12868 72525 break;
12869
12870 case LWPNHYSZ:
12871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72542 times.
72542 if(0!=(s=checkLWpn(ri->lwpn)))
12872 72542 (((weapon*)s)->hit_height)=(value/10000);
12873
12874 72542 break;
12875
12876 case LWPNHZSZ:
12877
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12878 6 (((weapon*)s)->hzsz)=(value/10000);
12879
12880 6 break;
12881
12882 case LWPNTXSZ:
12883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833 times.
833 if(0!=(s=checkLWpn(ri->lwpn)))
12884 833 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
12885
12886 833 break;
12887
12888 case LWPNTYSZ:
12889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833 times.
833 if(0!=(s=checkLWpn(ri->lwpn)))
12890 833 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
12891
12892 833 break;
12893
12894 case LWPNCOLLDET:
12895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18928 times.
18928 if(0!=(s=checkLWpn(ri->lwpn)))
12896 18928 (((weapon*)(s))->scriptcoldet) = value;
12897
12898 18928 break;
12899
12900 case LWPNENGINEANIMATE:
12901 if(0!=(s=checkLWpn(ri->lwpn)))
12902 (((weapon*)(s))->do_animation)=value;
12903
12904 break;
12905
12906 case LWPNPARENT:
12907 {
12908 //int32_t pitm = (vbound(value/10000,1,(MAXITEMS-1)));
12909
12910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if(0!=(s=checkLWpn(ri->lwpn)))
12911 42 (((weapon*)(s))->parentitem)=(vbound(value/10000,-1,(MAXITEMS-1)));
12912 42 break;
12913 }
12914
12915 case LWPNLEVEL:
12916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(0!=(s=checkLWpn(ri->lwpn)))
12917 12 (((weapon*)(s))->type)=value/10000;
12918
12919 12 break;
12920
12921 case LWPNSCRIPT:
12922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62002 times.
62002 if(0!=(s=checkLWpn(ri->lwpn)))
12923 {
12924 62002 (((weapon*)(s))->script)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
12925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62002 times.
62002 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
12926 {
12927
2/2
✓ Branch 0 taken 496016 times.
✓ Branch 1 taken 62002 times.
558018 for(int32_t q=0; q<8; q++)
12928 496016 (((weapon*)(s))->initD[q]) = 0;
12929 62002 }
12930 62002 on_reassign_script_engine_data(ScriptType::Lwpn, ri->lwpn);
12931 62002 }
12932 62002 break;
12933
12934 case LWPNUSEWEAPON:
12935
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 if(0!=(s=checkLWpn(ri->lwpn)))
12936 1130 (((weapon*)(s))->useweapon)=vbound(value/10000,0,255);
12937
12938 1130 break;
12939
12940 case LWPNUSEDEFENCE:
12941 if(0!=(s=checkLWpn(ri->lwpn)))
12942 (((weapon*)(s))->usedefense)=vbound(value/10000,0,255);
12943
12944 break;
12945
12946 case LWPNFALLCLK:
12947 if(0!=(s=checkLWpn(ri->lwpn)))
12948 {
12949 if(((weapon*)(s))->fallclk != 0 && value == 0)
12950 {
12951 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
12952 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
12953 }
12954 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
12955 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
12956 }
12957 break;
12958 case LWPNFALLCMB:
12959 if(0!=(s=checkLWpn(ri->lwpn)))
12960 {
12961 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
12962 }
12963 break;
12964 case LWPNDROWNCLK:
12965 if(0!=(s=checkLWpn(ri->lwpn)))
12966 {
12967 if(((weapon*)(s))->drownclk != 0 && value == 0)
12968 {
12969 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
12970 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
12971 }
12972 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
12973 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
12974 }
12975 break;
12976 case LWPNDROWNCMB:
12977 if(0!=(s=checkLWpn(ri->lwpn)))
12978 {
12979 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
12980 }
12981 break;
12982 case LWPNFAKEZ:
12983 if(0!=(s=checkLWpn(ri->lwpn)))
12984 {
12985 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12986 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
12987 }
12988
12989 break;
12990
12991 case LWPNGLOWRAD:
12992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527 times.
527 if(0!=(s=checkLWpn(ri->lwpn)))
12993 {
12994 527 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
12995 527 }
12996 527 break;
12997
12998 case LWPNGLOWSHP:
12999 if(0!=(s=checkLWpn(ri->lwpn)))
13000 {
13001 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
13002 }
13003 break;
13004
13005 case LWPNUNBL:
13006 if(0!=(s=checkLWpn(ri->lwpn)))
13007 {
13008 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
13009 }
13010 break;
13011
13012 case LWPNSHADOWSPR:
13013 if(0!=(s=checkLWpn(ri->lwpn)))
13014 {
13015 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
13016 }
13017 break;
13018 case LWSWHOOKED:
13019 break; //read-only
13020 case LWPNTIMEOUT:
13021 if(0!=(s=checkLWpn(ri->lwpn)))
13022 {
13023 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
13024 }
13025 break;
13026 case LWPNDEATHITEM:
13027 if(0!=(s=checkLWpn(ri->lwpn)))
13028 {
13029 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
13030 }
13031 break;
13032 case LWPNDEATHDROPSET:
13033 if(0!=(s=checkLWpn(ri->lwpn)))
13034 {
13035 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
13036 }
13037 break;
13038 case LWPNDEATHIPICKUP:
13039 if(0!=(s=checkLWpn(ri->lwpn)))
13040 {
13041 ((weapon*)(s))->death_item_pflags = value/10000;
13042 }
13043 break;
13044 case LWPNDEATHSPRITE:
13045 if(0!=(s=checkLWpn(ri->lwpn)))
13046 {
13047 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
13048 }
13049 break;
13050 case LWPNDEATHSFX:
13051 if(0!=(s=checkLWpn(ri->lwpn)))
13052 {
13053 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
13054 }
13055 break;
13056 case LWPNLIFTLEVEL:
13057 if(0!=(s=checkLWpn(ri->lwpn)))
13058 {
13059 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
13060 }
13061 break;
13062 case LWPNLIFTTIME:
13063 if(0!=(s=checkLWpn(ri->lwpn)))
13064 {
13065 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
13066 }
13067 break;
13068 case LWPNLIFTHEIGHT:
13069 if(0!=(s=checkLWpn(ri->lwpn)))
13070 {
13071 ((weapon*)(s))->lift_height = zslongToFix(value);
13072 }
13073 break;
13074
13075 ///----------------------------------------------------------------------------------------------------//
13076 //EWeapon Variables
13077 case EWPNSCALE:
13078 if ( get_qr(qr_OLDSPRITEDRAWS) )
13079 {
13080 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
13081 break;
13082 }
13083 if(0!=(s=checkEWpn(ri->ewpn)))
13084 ((weapon*)s)->scale=(zfix)(value/100.0);
13085
13086 break;
13087
13088 case EWPNX:
13089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390183 times.
390183 if(0!=(s=checkEWpn(ri->ewpn)))
13090
2/2
✓ Branch 0 taken 38744 times.
✓ Branch 1 taken 351439 times.
390183 ((weapon*)s)->x = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
13091
13092 390183 break;
13093
13094 case SPRITEMAXEWPN:
13095 {
13096 //No bounds check, as this is a universal function and works from NULL pointers!
13097 1 Ewpns.setMax(vbound((value/10000),1,MAX_EWPN_SPRITES));
13098 1 break;
13099 }
13100
13101 case EWPNY:
13102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390780 times.
390780 if(0!=(s=checkEWpn(ri->ewpn)))
13103
2/2
✓ Branch 0 taken 38610 times.
✓ Branch 1 taken 352170 times.
390780 ((weapon*)s)->y = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
13104
13105 390780 break;
13106
13107 case EWPNZ:
13108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57530 times.
57530 if(0!=(s=checkEWpn(ri->ewpn)))
13109 {
13110
2/2
✓ Branch 0 taken 1291 times.
✓ Branch 1 taken 56239 times.
57530 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
13111
2/2
✓ Branch 0 taken 57119 times.
✓ Branch 1 taken 411 times.
57530 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
13112 57530 }
13113
13114 57530 break;
13115
13116 case EWPNJUMP:
13117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55587 times.
55587 if(0!=(s=checkEWpn(ri->ewpn)))
13118 55587 ((weapon*)s)->fall=zslongToFix(value)*-100;
13119
13120 55587 break;
13121
13122 case EWPNFAKEJUMP:
13123 if(0!=(s=checkEWpn(ri->ewpn)))
13124 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
13125
13126 break;
13127
13128 case EWPNDIR:
13129
1/2
✓ Branch 0 taken 227256 times.
✗ Branch 1 not taken.
227256 if(0!=(s=checkEWpn(ri->ewpn)))
13130 {
13131 227256 ((weapon*)s)->dir=(value/10000);
13132 227256 ((weapon*)s)->doAutoRotate(true);
13133 227256 }
13134
13135 227256 break;
13136
13137 case EWPNLEVEL:
13138
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if(0!=(s=checkEWpn(ri->ewpn)))
13139 117 ((weapon*)s)->type=(value/10000);
13140
13141 117 break;
13142
13143 case EWPNGRAVITY:
13144 if(0!=(s=checkEWpn(ri->ewpn)))
13145 {
13146 if(value)
13147 ((weapon*)s)->moveflags |= move_obeys_grav;
13148 else
13149 ((weapon*)s)->moveflags &= ~move_obeys_grav;
13150 }
13151 break;
13152
13153 case EWPNSTEP:
13154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372485 times.
372485 if(0!=(s=checkEWpn(ri->ewpn)))
13155 {
13156
3/4
✓ Branch 0 taken 350322 times.
✓ Branch 1 taken 22163 times.
✓ Branch 2 taken 350322 times.
✗ Branch 3 not taken.
372485 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
13157 {
13158 372485 ((weapon*)s)->step= zslongToFix(value / 100);
13159 372485 }
13160 else
13161 {
13162 //old, buggy code replication, round two: Go! -Z
13163 //zfix val = zslongToFix(value);
13164 //val.doFloor();
13165 //((weapon*)s)->step = ((val / 100.0).getFloat());
13166
13167 //old, buggy code replication, round THREE: Go! -Z
13168 ((weapon*)s)->step = ((value/10000)/100.0);
13169 }
13170 372485 }
13171
13172 372485 break;
13173
13174 case EWPNANGLE:
13175
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 220884 times.
220890 if(0!=(s=checkEWpn(ri->ewpn)))
13176 {
13177 220884 ((weapon*)s)->angle=(double)(value/10000.0);
13178 220884 ((weapon*)(s))->doAutoRotate();
13179 220884 }
13180
13181 220890 break;
13182
13183 case EWPNDEGANGLE:
13184 if(0!=(s=checkEWpn(ri->ewpn)))
13185 {
13186 double rangle = (value / 10000.0) * (PI / 180.0);
13187 ((weapon*)s)->angle=(double)(rangle);
13188 ((weapon*)(s))->doAutoRotate();
13189 }
13190
13191 break;
13192
13193 case EWPNVX:
13194 if(0!=(s=checkEWpn(ri->ewpn)))
13195 {
13196 double vy;
13197 double vx = (value / 10000.0);
13198 if (((weapon*)(s))->angular)
13199 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
13200 else
13201 {
13202 switch(NORMAL_DIR(((weapon*)(s))->dir))
13203 {
13204 case l_up:
13205 case r_up:
13206 case up:
13207 vy = -1.0*((weapon*)s)->step;
13208 break;
13209 case l_down:
13210 case r_down:
13211 case down:
13212 vy = ((weapon*)s)->step;
13213 break;
13214
13215 default:
13216 vy = 0;
13217 break;
13218 }
13219 }
13220 ((weapon*)s)->angular = true;
13221 ((weapon*)s)->angle=atan2(vy, vx);
13222 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
13223 ((weapon*)(s))->doAutoRotate();
13224 }
13225
13226 break;
13227
13228 case EWPNVY:
13229 if(0!=(s=checkEWpn(ri->ewpn)))
13230 {
13231 double vx;
13232 double vy = (value / 10000.0);
13233 if (((weapon*)(s))->angular)
13234 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
13235 else
13236 {
13237 switch(NORMAL_DIR(((weapon*)(s))->dir))
13238 {
13239 case l_up:
13240 case l_down:
13241 case left:
13242 vx = -1.0*((weapon*)s)->step;
13243 break;
13244 case r_down:
13245 case r_up:
13246 case right:
13247 vx = ((weapon*)s)->step;
13248 break;
13249
13250 default:
13251 vx = 0;
13252 break;
13253 }
13254 }
13255 ((weapon*)s)->angular = true;
13256 ((weapon*)s)->angle=atan2(vy, vx);
13257 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
13258 ((weapon*)(s))->doAutoRotate();
13259 }
13260
13261 break;
13262
13263 case EWPNANGULAR:
13264
1/2
✓ Branch 0 taken 208988 times.
✗ Branch 1 not taken.
208988 if(0!=(s=checkEWpn(ri->ewpn)))
13265 {
13266 208988 ((weapon*)s)->angular=(value!=0);
13267 208988 ((weapon*)(s))->doAutoRotate(false, true);
13268 208988 }
13269
13270 208988 break;
13271
13272 case EWPNAUTOROTATE:
13273 if(0!=(s=checkEWpn(ri->ewpn)))
13274 {
13275 ((weapon*)s)->autorotate=(value!=0);
13276 ((weapon*)(s))->doAutoRotate(false, true);
13277 }
13278
13279 break;
13280
13281 case EWPNBEHIND:
13282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5420 times.
5420 if(0!=(s=checkEWpn(ri->ewpn)))
13283 5420 ((weapon*)s)->behind=(value!=0);
13284
13285 5420 break;
13286
13287 case EWPNDRAWTYPE:
13288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12175 times.
12175 if(0!=(s=checkEWpn(ri->ewpn)))
13289 12175 ((weapon*)s)->drawstyle=(value/10000);
13290
13291 12175 break;
13292
13293 case EWPNPOWER:
13294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210232 times.
210232 if(0!=(s=checkEWpn(ri->ewpn)))
13295 210232 ((weapon*)s)->power=(value/10000);
13296
13297 210232 break;
13298
13299 case EWPNDEAD:
13300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114186 times.
114186 if(0!=(s=checkEWpn(ri->ewpn)))
13301 {
13302 114186 auto dead = value/10000;
13303 114186 ((weapon*)s)->dead=dead;
13304
2/2
✓ Branch 0 taken 28037 times.
✓ Branch 1 taken 86149 times.
114186 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
13305 114186 }
13306
13307 114186 break;
13308
13309 case EWPNID:
13310 if(0!=(s=checkEWpn(ri->ewpn)))
13311 ((weapon*)s)->id=(value/10000);
13312
13313 break;
13314
13315 case EWPNTILE:
13316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74446 times.
74446 if(0!=(s=checkEWpn(ri->ewpn)))
13317 74446 ((weapon*)s)->tile=(value/10000);
13318
13319 74446 break;
13320
13321 case EWPNSCRIPTTILE:
13322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if(0!=(s=checkEWpn(ri->ewpn)))
13323 178 ((weapon*)s)->scripttile=vbound((value/10000),-1, NEWMAXTILES-1);
13324
13325 178 break;
13326
13327 case EWPNSCRIPTFLIP:
13328 if(0!=(s=checkEWpn(ri->ewpn)))
13329 ((weapon*)s)->scriptflip=vbound((value/10000),-1, 127);
13330
13331 break;
13332
13333 case EWPNCSET:
13334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35337 times.
35337 if(0!=(s=checkEWpn(ri->ewpn)))
13335 35337 ((weapon*)s)->cs=(value/10000)&15;
13336
13337 35337 break;
13338
13339 case EWPNFLASHCSET:
13340 if(0!=(s=checkEWpn(ri->ewpn)))
13341 (((weapon*)s)->o_cset)|=(value/10000)<<4;
13342
13343 break;
13344
13345 case EWPNFRAMES:
13346
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
13347 41 ((weapon*)s)->frames=(value/10000);
13348
13349 41 break;
13350
13351 case EWPNFRAME:
13352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1039 times.
1039 if(0!=(s=checkEWpn(ri->ewpn)))
13353 1039 ((weapon*)s)->aframe=(value/10000);
13354
13355 1039 break;
13356
13357 case EWPNASPEED:
13358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
13359 41 ((weapon*)s)->o_speed=(value/10000);
13360
13361 41 break;
13362
13363 case EWPNFLASH:
13364
1/2
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
549 if(0!=(s=checkEWpn(ri->ewpn)))
13365 549 ((weapon*)s)->flash=(value/10000);
13366
13367 549 break;
13368
13369 case EWPNFLIP:
13370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78832 times.
78832 if(0!=(s=checkEWpn(ri->ewpn)))
13371 78832 ((weapon*)s)->flip=(value/10000);
13372
13373 78832 break;
13374
13375 case EWPNROTATION:
13376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if ( get_qr(qr_OLDSPRITEDRAWS) )
13377 {
13378 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
13379 break;
13380 }
13381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if(0!=(s=checkEWpn(ri->ewpn)))
13382 1104 ((weapon*)s)->rotation=(value/10000);
13383
13384 1104 break;
13385
13386 case EWPNEXTEND:
13387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 156969 times.
156969 if(0!=(s=checkEWpn(ri->ewpn)))
13388 156969 ((weapon*)s)->extend=(value/10000);
13389
13390 156969 break;
13391
13392 case EWPNOTILE:
13393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4552 times.
4552 if(0!=(s=checkEWpn(ri->ewpn)))
13394 {
13395 4552 ((weapon*)s)->o_tile=(value/10000);
13396 4552 ((weapon*)s)->ref_o_tile=(value/10000);
13397 4552 }
13398
13399 4552 break;
13400
13401 case EWPNOCSET:
13402 if(0!=(s=checkEWpn(ri->ewpn)))
13403 (((weapon*)s)->o_cset)|=(value/10000)&15;
13404
13405 break;
13406
13407 case EWPNHXOFS:
13408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194229 times.
194229 if(0!=(s=checkEWpn(ri->ewpn)))
13409 194229 (((weapon*)s)->hxofs)=(value/10000);
13410
13411 194229 break;
13412
13413 case EWPNHYOFS:
13414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193736 times.
193736 if(0!=(s=checkEWpn(ri->ewpn)))
13415 193736 (((weapon*)s)->hyofs)=(value/10000);
13416
13417 193736 break;
13418
13419 case EWPNXOFS:
13420
2/2
✓ Branch 0 taken 84990 times.
✓ Branch 1 taken 4 times.
84994 if(0!=(s=checkEWpn(ri->ewpn)))
13421 84990 (((weapon*)s)->xofs)=(zfix)(value/10000);
13422
13423 84994 break;
13424
13425 case EWPNYOFS:
13426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 if(0!=(s=checkEWpn(ri->ewpn)))
13427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
13428
13429 44193 break;
13430
13431 case EWPNSHADOWXOFS:
13432 if(0!=(s=checkEWpn(ri->ewpn)))
13433 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
13434
13435 break;
13436
13437 case EWPNSHADOWYOFS:
13438 if(0!=(s=checkEWpn(ri->ewpn)))
13439 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
13440
13441 break;
13442
13443 case EWPNZOFS:
13444 if(0!=(s=checkEWpn(ri->ewpn)))
13445 (((weapon*)s)->zofs)=(zfix)(value/10000);
13446
13447 break;
13448
13449 case EWPNHXSZ:
13450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325611 times.
325611 if(0!=(s=checkEWpn(ri->ewpn)))
13451 325611 (((weapon*)s)->hit_width)=(value/10000);
13452
13453 325611 break;
13454
13455 case EWPNHYSZ:
13456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325024 times.
325024 if(0!=(s=checkEWpn(ri->ewpn)))
13457 325024 (((weapon*)s)->hit_height)=(value/10000);
13458
13459 325024 break;
13460
13461 case EWPNHZSZ:
13462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(0!=(s=checkEWpn(ri->ewpn)))
13463 44 (((weapon*)s)->hzsz)=(value/10000);
13464
13465 44 break;
13466
13467 case EWPNTXSZ:
13468
1/2
✓ Branch 0 taken 202345 times.
✗ Branch 1 not taken.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
13469 202345 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
13470
13471 202345 break;
13472
13473 case EWPNTYSZ:
13474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202345 times.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
13475 202345 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
13476
13477 202345 break;
13478
13479 case EWPNCOLLDET:
13480
1/2
✓ Branch 0 taken 31616 times.
✗ Branch 1 not taken.
31616 if(0!=(s=checkEWpn(ri->ewpn)))
13481 31616 (((weapon*)(s))->scriptcoldet)=value;
13482
13483 31616 break;
13484
13485 case EWPNENGINEANIMATE:
13486 if(0!=(s=checkEWpn(ri->ewpn)))
13487 (((weapon*)(s))->do_animation)=value;
13488
13489 break;
13490
13491
13492 case EWPNPARENTUID:
13493 if(0!=(s=checkEWpn(ri->ewpn)))
13494 s->setParent(sprite::getByUID(value));
13495 break;
13496
13497 case EWPNPARENT:
13498 if(0!=(s=checkEWpn(ri->ewpn)))
13499 (((weapon*)(s))->parentid)= ( (get_qr(qr_OLDEWPNPARENT)) ? value / 10000 : value );
13500
13501 break;
13502
13503 case EWPNSCRIPT:
13504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if(0!=(s=checkEWpn(ri->ewpn)))
13505 {
13506 1621 (((weapon*)(s))->script)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
13507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
13508 {
13509
2/2
✓ Branch 0 taken 12968 times.
✓ Branch 1 taken 1621 times.
14589 for(int32_t q=0; q<8; q++)
13510 12968 (((weapon*)(s))->initD[q]) = 0;
13511 1621 }
13512 1621 on_reassign_script_engine_data(ScriptType::Ewpn, ri->ewpn);
13513 1621 }
13514 1621 break;
13515
13516 case EWPNFALLCLK:
13517 if(0!=(s=checkEWpn(ri->ewpn)))
13518 {
13519 if(((weapon*)(s))->fallclk != 0 && value == 0)
13520 {
13521 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
13522 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
13523 }
13524 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
13525 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
13526 }
13527 break;
13528 case EWPNFALLCMB:
13529 if(0!=(s=checkEWpn(ri->ewpn)))
13530 {
13531 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
13532 }
13533 break;
13534 case EWPNDROWNCLK:
13535 if(0!=(s=checkEWpn(ri->ewpn)))
13536 {
13537 if(((weapon*)(s))->drownclk != 0 && value == 0)
13538 {
13539 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
13540 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
13541 }
13542 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
13543 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
13544 }
13545 break;
13546 case EWPNDROWNCMB:
13547 if(0!=(s=checkEWpn(ri->ewpn)))
13548 {
13549 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
13550 }
13551 break;
13552 case EWPNFAKEZ:
13553 if(0!=(s=checkEWpn(ri->ewpn)))
13554 {
13555 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
13556 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
13557 }
13558
13559 break;
13560
13561 case EWPNGLOWRAD:
13562
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(0!=(s=checkEWpn(ri->ewpn)))
13563 {
13564 4 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
13565 4 }
13566 4 break;
13567 case EWPNGLOWSHP:
13568 if(0!=(s=checkEWpn(ri->ewpn)))
13569 {
13570 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
13571 }
13572 break;
13573
13574 case EWPNUNBL:
13575 if(0!=(s=checkEWpn(ri->ewpn)))
13576 {
13577 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
13578 }
13579 break;
13580
13581 case EWPNSHADOWSPR:
13582 if(0!=(s=checkEWpn(ri->ewpn)))
13583 {
13584 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
13585 }
13586 break;
13587 case EWSWHOOKED:
13588 break; //read-only
13589 case EWPNTIMEOUT:
13590 if(0!=(s=checkEWpn(ri->ewpn)))
13591 {
13592 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
13593 }
13594 break;case EWPNDEATHITEM:
13595 if(0!=(s=checkEWpn(ri->ewpn)))
13596 {
13597 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
13598 }
13599 break;
13600 case EWPNDEATHDROPSET:
13601 if(0!=(s=checkEWpn(ri->ewpn)))
13602 {
13603 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
13604 }
13605 break;
13606 case EWPNDEATHIPICKUP:
13607 if(0!=(s=checkEWpn(ri->ewpn)))
13608 {
13609 ((weapon*)(s))->death_item_pflags = value/10000;
13610 }
13611 break;
13612 case EWPNDEATHSPRITE:
13613 if(0!=(s=checkEWpn(ri->ewpn)))
13614 {
13615 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
13616 }
13617 break;
13618 case EWPNDEATHSFX:
13619 if(0!=(s=checkEWpn(ri->ewpn)))
13620 {
13621 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
13622 }
13623 break;
13624 case EWPNLIFTLEVEL:
13625 if(0!=(s=checkEWpn(ri->ewpn)))
13626 {
13627 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
13628 }
13629 break;
13630 case EWPNLIFTTIME:
13631 if(0!=(s=checkEWpn(ri->ewpn)))
13632 {
13633 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
13634 }
13635 break;
13636 case EWPNLIFTHEIGHT:
13637 if(0!=(s=checkEWpn(ri->ewpn)))
13638 {
13639 ((weapon*)(s))->lift_height = zslongToFix(value);
13640 }
13641 break;
13642
13643 ///----------------------------------------------------------------------------------------------------//
13644 //Screen Information
13645
13646 case SCREENSCRDATASIZE:
13647 {
13648 int index = map_screen_index(cur_map, ri->screenref);
13649 if (index < 0) break;
13650
13651 game->scriptDataResize(index, value/10000);
13652 break;
13653 }
13654
13655 case GAMEGUYCOUNTD:
13656 {
13657 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
13658 game->guys[mi] = value / 10000;
13659 break;
13660 }
13661
13662 ///----------------------------------------------------------------------------------------------------//
13663 //BottleTypes
13664
13665 case BOTTLENEXT:
13666 {
13667 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
13668 {
13669 ptr->next_type = vbound(value/10000, 0, 64);
13670 }
13671 }
13672 break;
13673
13674 ///----------------------------------------------------------------------------------------------------//
13675 //Viewport
13676
13677 case VIEWPORT_TARGET:
13678 {
13679
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (auto s = ResolveBaseSprite(value))
13680 6 set_viewport_sprite(s);
13681 }
13682 6 break;
13683
13684 case VIEWPORT_MODE:
13685 {
13686 4 int val = value;
13687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (BC::checkBounds(val, (int)ViewportMode::First, (int)ViewportMode::Last) != SH::_NoError)
13688 {
13689 break;
13690 }
13691
13692 4 viewport_mode = (ViewportMode)val;
13693 }
13694 4 break;
13695
13696 case VIEWPORT_X:
13697 {
13698 360 viewport.x = value / 10000;
13699 }
13700 360 break;
13701
13702 case VIEWPORT_Y:
13703 {
13704 360 viewport.y = value / 10000;
13705 }
13706 360 break;
13707
13708 case VIEWPORT_WIDTH:
13709 {
13710 int val = value / 10000;
13711 if (BC::checkBounds(val, 0, 256) != SH::_NoError)
13712 break;
13713
13714 viewport.w = val;
13715 }
13716 break;
13717
13718 case VIEWPORT_HEIGHT:
13719 {
13720 int val = value / 10000;
13721 if (BC::checkBounds(val, 0, 232) != SH::_NoError)
13722 break;
13723
13724 viewport.h = val;
13725 }
13726 break;
13727
13728 ///----------------------------------------------------------------------------------------------------//
13729 //Screen Variables
13730
13731 #define SET_SCREENDATA_VAR_INT32(member, str) \
13732 { \
13733 get_scr(ri->screenref)->member = vbound((value / 10000),-214747,214747); \
13734 } \
13735
13736 #define SET_SCREENDATA_VAR_INT16(member, str) \
13737 { \
13738 get_scr(ri->screenref)->member = vbound((value / 10000),0,32767); \
13739 } \
13740
13741 #define SET_SCREENDATA_VAR_BYTE(member, str) \
13742 { \
13743 get_scr(ri->screenref)->member = vbound((value / 10000),0,255); \
13744 } \
13745
13746 #define SET_SCREENDATA_BYTE_INDEX(member, str, indexbound) \
13747 { \
13748 int32_t indx = ri->d[rINDEX] / 10000; \
13749 get_scr(ri->screenref)->member[indx] = vbound((value / 10000),0,255); \
13750 }
13751
13752 ///max screen id is higher! vbound properly... -Z
13753 #define SET_SCREENDATA_LAYERSCREEN_INDEX(member, str, indexbound) \
13754 { \
13755 int32_t indx = ri->d[rINDEX] / 10000; \
13756 int32_t scrn_id = value/10000; \
13757 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
13758 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
13759 { \
13760 } \
13761 else if ( scrn_id > MAPSCRS ) \
13762 { \
13763 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
13764 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
13765 } \
13766 else get_scr(ri->screenref)->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
13767 }
13768
13769 #define SET_SCREENDATA_FLAG(member, str) \
13770 { \
13771 int32_t flag = (value/10000); \
13772 if ( flag != 0 ) \
13773 { \
13774 get_scr(ri->screenref)->member|=flag; \
13775 } \
13776 else get_scr(ri->screenref)->.member|= ~flag; \
13777 } \
13778
13779 #define SET_SCREENDATA_BOOL_INDEX(member, str, indexbound) \
13780 { \
13781 int32_t indx = ri->d[rINDEX] / 10000; \
13782 if(indx < 0 || indx > indexbound ) \
13783 { \
13784 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", (indx), str); \
13785 break; \
13786 } \
13787 get_scr(ri->screenref)->member[indx] =( (value/10000) ? 1 : 0 ); \
13788 }
13789
13790 case SCREENDATAVALID:
13791 {
13792 SET_SCREENDATA_VAR_BYTE(valid, "Valid"); //b
13793 mark_current_region_handles_dirty();
13794 break;
13795 }
13796 case SCREENDATAGUY: SET_SCREENDATA_VAR_BYTE(guy, "Guy"); break; //b
13797 case SCREENDATASTRING: SET_SCREENDATA_VAR_INT32(str, "String"); break; //w
13798 case SCREENDATAROOM: SET_SCREENDATA_VAR_BYTE(room, "RoomType"); break; //b
13799 case SCREENDATAITEM:
13800 {
13801 auto v = vbound((value / 10000),-1,255);
13802 auto scr = get_scr(ri->screenref);
13803 if(v > -1)
13804 scr->item = v;
13805 scr->hasitem = v > -1;
13806 break;
13807 }
13808 case SCREENDATAHASITEM: SET_SCREENDATA_VAR_BYTE(hasitem, "HasItem"); break; //b
13809 case SCREENDATADOORCOMBOSET: SET_SCREENDATA_VAR_INT32(door_combo_set, "DoorComboSet"); break; //w
13810 case SCREENDATAWARPRETURNC: SET_SCREENDATA_VAR_INT32(warpreturnc, "WarpReturnC"); break; //w
13811 case SCREENDATASTAIRX: SET_SCREENDATA_VAR_BYTE(stairx, "StairsX"); break; //b
13812 case SCREENDATASTAIRY: SET_SCREENDATA_VAR_BYTE(stairy, "StairsY"); break; //b
13813 case SCREENDATAITEMX: SET_SCREENDATA_VAR_BYTE(itemx, "ItemX"); break; //itemx
13814 case SCREENDATAITEMY: SET_SCREENDATA_VAR_BYTE(itemy, "ItemY"); break; //itemy
13815 case SCREENDATACOLOUR: SET_SCREENDATA_VAR_INT32(color, "CSet"); break; //w
13816 case SCREENDATAENEMYFLAGS: SET_SCREENDATA_VAR_BYTE(flags11, "EnemyFlags"); break; //b
13817 case SCREENDATADOOR: SET_SCREENDATA_BYTE_INDEX(door, "Door", 3); break; //b, 4 of these
13818 case SCREENDATAEXITDIR: SET_SCREENDATA_VAR_BYTE(exitdir, "ExitDir"); break; //b
13819 case SCREENDATAPATTERN: SET_SCREENDATA_VAR_BYTE(pattern, "Pattern"); break; //b
13820 case SCREENDATAWARPARRIVALX: SET_SCREENDATA_VAR_BYTE(warparrivalx, "WarpArrivalX"); break; //b
13821 case SCREENDATAWARPARRIVALY: SET_SCREENDATA_VAR_BYTE(warparrivaly, "WarpArrivalY"); break; //b
13822 case SCREENDATASIDEWARPINDEX: SET_SCREENDATA_VAR_BYTE(sidewarpindex, "SideWarpIndex"); break; //b
13823 case SCREENDATAUNDERCOMBO: SET_SCREENDATA_VAR_INT32(undercombo, "Undercombo"); break; //w
13824 case SCREENDATAUNDERCSET: SET_SCREENDATA_VAR_BYTE(undercset, "UnderCSet"); break; //b
13825 case SCREENDATACATCHALL: SET_SCREENDATA_VAR_INT32(catchall, "Catchall"); break; //W
13826
13827 case SCREENDATACSENSITIVE: SET_SCREENDATA_VAR_BYTE(csensitive, "CSensitive"); break; //B
13828 case SCREENDATANORESET: SET_SCREENDATA_VAR_INT32(noreset, "NoReset"); break; //W
13829 case SCREENDATANOCARRY: SET_SCREENDATA_VAR_INT32(nocarry, "NoCarry"); break; //W
13830
13831 case SCREENDATATIMEDWARPTICS: SET_SCREENDATA_VAR_INT32(timedwarptics, "TimedWarpTimer"); break; //W
13832 case SCREENDATANEXTMAP: SET_SCREENDATA_VAR_BYTE(nextmap, "NextMap"); break; //B
13833 case SCREENDATANEXTSCREEN: SET_SCREENDATA_VAR_BYTE(nextscr, "NextScreen"); break; //B
13834 case SCREENDATAVIEWX: break;//SET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
13835 case SCREENDATAVIEWY: break;//SET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
13836 case SCREENDATASCREENWIDTH: break;//SET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
13837 case SCREENDATASCREENHEIGHT: break;//SET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
13838 case SCREENDATAENTRYX:
13839 {
13840 30 int32_t newx = vbound((value/10000),0,255);
13841 30 get_scr(ri->screenref)->entry_x = newx;
13842
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
13843 {
13844 20 Hero.respawn_x = (zfix)(newx);
13845 20 }
13846 30 break;
13847 }
13848 case SCREENDATAENTRYY:
13849 {
13850
13851 30 int32_t newy = vbound((value/10000),0,175);
13852 30 get_scr(ri->screenref)->entry_y = newy;
13853
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
13854 {
13855 20 Hero.respawn_y = (zfix)(newy);
13856 20 }
13857 30 break; //B
13858 }
13859
13860 case SCREENDATANUMFF:
13861 {
13862 break;
13863 }
13864
13865 case SCREENDATAFFINITIALISED:
13866 {
13867 int32_t indx = ri->d[rINDEX] / 10000;
13868 if (indx < 0 || indx > MAX_FFCID)
13869 {
13870 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", "FFCRunning", (indx));
13871 break;
13872 }
13873 get_script_engine_data(ScriptType::FFC, indx).initialized = (value/10000) ? true : false;
13874 }
13875 break;
13876
13877 case SCREENDATASCRIPTENTRY:
13878 {
13879 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
13880 }
13881 break;
13882 case SCREENDATASCRIPTOCCUPANCY:
13883 {
13884 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
13885 }
13886 break;
13887 case SCREENDATASCRIPTEXIT:
13888 {
13889 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
13890 }
13891 break;
13892
13893 case SCREENDATAOCEANSFX:
13894 {
13895 int32_t v = vbound(value/10000, 0, 255);
13896 auto scr = get_scr(ri->screenref);
13897 if (scr == hero_scr && scr->oceansfx != v)
13898 {
13899 stop_sfx(scr->oceansfx);
13900 scr->oceansfx = v;
13901 cont_sfx(scr->oceansfx);
13902 }
13903 break;
13904 }
13905 case SCREENDATABOSSSFX: SET_SCREENDATA_VAR_BYTE(bosssfx, "BossSFX"); break; //B
13906 10 case SCREENDATASECRETSFX: SET_SCREENDATA_VAR_BYTE(secretsfx, "SecretSFX"); break; //B
13907 case SCREENDATAHOLDUPSFX: SET_SCREENDATA_VAR_BYTE(holdupsfx, "ItemSFX"); break; //B
13908 case SCREENDATASCREENMIDI:
13909 {
13910 get_scr(ri->screenref)->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
13911 break;
13912 }
13913 case SCREENDATALENSLAYER: SET_SCREENDATA_VAR_BYTE(lens_layer, "LensLayer"); break; //B, OLD QUESTS ONLY?
13914
13915 case SCREENDATAGUYCOUNT:
13916 {
13917 int mi = mapind(cur_map, ri->screenref);
13918 if(mi > -1)
13919 game->guys[mi] = vbound(value/10000,10,0);
13920 break;
13921 }
13922 case SCREENDATAEXDOOR:
13923 {
13924 int mi = mapind(cur_map, ri->screenref);
13925 if(mi < 0) break;
13926 int dir = SH::read_stack(ri->sp+1) / 10000;
13927 int ind = SH::read_stack(ri->sp+0) / 10000;
13928 if(unsigned(dir) > 3)
13929 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->SetExDoor()'; must be 0-3\n", dir);
13930 else if(unsigned(ind) > 7)
13931 Z_scripterrlog("Invalid index '%d' passed to 'Screen->SetExDoor()'; must be 0-7\n", ind);
13932 else
13933 set_xdoorstate_mi(mi, dir, ind);
13934 break;
13935 }
13936
13937 //These use the same method as SetScreenD
13938 case SCREENWIDTH:
13939 // FFScript::set_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13940 break;
13941
13942 case SCREENHEIGHT:
13943 // FFScript::set_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13944 break;
13945
13946 case SCREENVIEWX:
13947 // FFScript::set_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13948 break;
13949
13950 case SCREENVIEWY:
13951 // FFScript::set_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13952 break;
13953
13954 //These use the method of SetScreenEnemy
13955
13956 case GDD:
13957 write_array(game->global_d, ri->d[rINDEX] / 10000, value);
13958 break;
13959
13960 case SDDD:
13961 27297 FFScript::set_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2]/10000, value);
13962 27297 break;
13963
13964 case SDDDD:
13965 536 FFScript::set_screen_d(ri->d[rINDEX2]/10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1]/10000, value);
13966 536 break;
13967
13968 case SCREENSCRIPT:
13969 {
13970 mapscr* scr = get_scr(ri->screenref);
13971
13972 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
13973 {
13974 for(int32_t q=0; q<8; q++)
13975 scr->screeninitd[q] = 0;
13976 }
13977
13978 scr->script=vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
13979 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
13980 break;
13981 }
13982
13983 case LIT:
13984 900 set_lights(value);
13985 900 break;
13986
13987 case WAVY:
13988 7396 wavy=value/10000;
13989 7396 break;
13990
13991 case QUAKE:
13992 6502 quakeclk=value/10000;
13993 6502 break;
13994
13995 case ROOMTYPE:
13996 get_scr(ri->screenref)->room=value/10000; break; //this probably doesn't work too well...
13997
13998 case ROOMDATA:
13999 11 get_scr(ri->screenref)->catchall=value/10000;
14000 11 break;
14001
14002 case PUSHBLOCKLAYER:
14003 mblock2.blockLayer=vbound(value/10000, 0, 6);
14004 break;
14005
14006 case PUSHBLOCKCOMBO:
14007 mblock2.bcombo=value/10000;
14008 break;
14009
14010 case PUSHBLOCKCSET:
14011 mblock2.cs=value/10000;
14012 mblock2.oldcset=value/10000;
14013 break;
14014
14015 case UNDERCOMBO:
14016 get_scr(ri->screenref)->undercombo=value/10000;
14017 break;
14018
14019 case UNDERCSET:
14020 get_scr(ri->screenref)->undercset=value/10000;
14021 break;
14022
14023 case SCREEN_DRAW_ORIGIN:
14024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39294 times.
39294 if (BC::checkBounds(value, (int)DrawOrigin::First, (int)DrawOrigin::Last) != SH::_NoError)
14025 break;
14026
14027 39294 ri->screen_draw_origin = (DrawOrigin)value;
14028 39294 break;
14029
14030 case SCREEN_DRAW_ORIGIN_TARGET:
14031 {
14032
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5310 times.
5310 if (ResolveBaseSprite(value))
14033 5310 ri->screen_draw_origin_target = value;
14034
14035 5310 break;
14036 }
14037
14038 ///----------------------------------------------------------------------------------------------------//
14039 //New Datatype Variables
14040
14041 ///----------------------------------------------------------------------------------------------------//
14042 //spritedata sp-> Variables
14043 case SPRITEDATATILE: SET_SPRITEDATA_VAR_INT(tile, "Tile"); break;
14044 case SPRITEDATAMISC: SET_SPRITEDATA_VAR_BYTE(misc, "Misc"); break;
14045 case SPRITEDATACSETS:
14046 {
14047 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
14048 {
14049 Z_scripterrlog("Invalid Sprite ID passed to spritedata->CSet: %d\n", (ri->spritedataref*10000));
14050 }
14051 else
14052 {
14053 wpnsbuf[ri->spritedataref].csets &= 0xF0;
14054 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15);
14055 }
14056 break;
14057 }
14058 case SPRITEDATAFLCSET:
14059 {
14060 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
14061 {
14062 Z_scripterrlog("Invalid Sprite ID passed to spritedata->FlashCSet: %d\n", (ri->spritedataref*10000));
14063 }
14064 else
14065 {
14066 wpnsbuf[ri->spritedataref].csets &= 0x0F;
14067 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15)<<4;
14068 }
14069 break;
14070 }
14071 case SPRITEDATAFRAMES: SET_SPRITEDATA_VAR_BYTE(frames, "Frames"); break;
14072 case SPRITEDATASPEED: SET_SPRITEDATA_VAR_BYTE(speed, "Speed"); break;
14073 case SPRITEDATATYPE: SET_SPRITEDATA_VAR_BYTE(type, "Type"); break;
14074
14075 ///----------------------------------------------------------------------------------------------------//
14076 //mapdata m-> Variables
14077 //mapdata m-> Variables
14078
14079 #define SET_MAPDATA_VAR_INT32(member) \
14080 { \
14081 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14082 { \
14083 m->member = vbound((value / 10000),-214747,214747); \
14084 } \
14085 break; \
14086 } \
14087
14088 #define SET_MAPDATA_VAR_INT16(member) \
14089 { \
14090 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14091 { \
14092 m->member = vbound((value / 10000),0,32767); \
14093 } \
14094 break; \
14095 } \
14096
14097 #define SET_MAPDATA_VAR_BYTE(member) \
14098 { \
14099 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14100 { \
14101 m->member = vbound((value / 10000),0,255); \
14102 } \
14103 break; \
14104 } \
14105
14106 #define SET_MAPDATA_VAR_INDEX32(member, indexbound) \
14107 { \
14108 int32_t indx = ri->d[rINDEX] / 10000; \
14109 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14110 { \
14111 } \
14112 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14113 { \
14114 m->member[indx] = vbound((value / 10000),-214747,214747); \
14115 } \
14116 break; \
14117 } \
14118
14119 #define SET_MAPDATA_VAR_INDEX16(member, indexbound) \
14120 { \
14121 int32_t indx = ri->d[rINDEX] / 10000; \
14122 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14123 { \
14124 } \
14125 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14126 { \
14127 m->member[indx] = vbound((value / 10000),-32767,32767); \
14128 } \
14129 break; \
14130 } \
14131
14132 #define SET_MAPDATA_BYTE_INDEX(member, indexbound) \
14133 { \
14134 int32_t indx = ri->d[rINDEX] / 10000; \
14135 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14136 { \
14137 } \
14138 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14139 { \
14140 m->member[indx] = vbound((value / 10000),0,255); \
14141 } \
14142 break; \
14143 }\
14144
14145 #define SET_MAPDATA_LAYER_INDEX(member, indexbound) \
14146 { \
14147 int32_t indx = ri->d[rINDEX] / 10000; \
14148 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
14149 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
14150 { \
14151 } \
14152 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14153 { \
14154 m->member[indx-1] = vbound((value / 10000),0,255); \
14155 } \
14156 break; \
14157 } \
14158
14159 #define SET_MAPDATA_LAYERSCREEN_INDEX(member, indexbound) \
14160 { \
14161 int32_t indx = ri->d[rINDEX] / 10000; \
14162 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
14163 int32_t scrn_id = value/10000; \
14164 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
14165 { \
14166 } \
14167 else if ( scrn_id > MAPSCRS ) \
14168 { \
14169 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
14170 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
14171 } \
14172 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14173 { \
14174 m->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
14175 } \
14176 break; \
14177 }\
14178
14179 #define SET_MAPDATA_BOOL_INDEX(member, indexbound) \
14180 { \
14181 int32_t indx = ri->d[rINDEX] / 10000; \
14182 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14183 { \
14184 } \
14185 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14186 { \
14187 m->member[indx] =( (value/10000) ? 1 : 0 ); \
14188 } \
14189 break; \
14190 } \
14191
14192
14193 #define SET_FFC_MAPDATA_BOOL_INDEX(member, indexbound) \
14194 { \
14195 int32_t index = ri->d[rINDEX] / 10000; \
14196 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
14197 { \
14198 handle.ffc->member =( (value/10000) ? 1 : 0 ); \
14199 } \
14200 break; \
14201 } \
14202
14203 #define SET_MAPDATA_FLAG(member) \
14204 { \
14205 int32_t flag = (value/10000); \
14206 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14207 { \
14208 if ( flag != 0 ) \
14209 { \
14210 m->member|=flag; \
14211 } \
14212 else m->.member|= ~flag; \
14213 } \
14214 break; \
14215 } \
14216
14217
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 case MAPDATAVALID: SET_MAPDATA_VAR_BYTE(valid); break; //b
14218 case MAPDATAGUY: SET_MAPDATA_VAR_BYTE(guy); break; //b
14219 case MAPDATASTRING: SET_MAPDATA_VAR_INT32(str); break; //w
14220 case MAPDATAROOM: SET_MAPDATA_VAR_BYTE(room); break; //b
14221 case MAPDATAITEM:
14222 {
14223 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14224 {
14225 auto v = vbound((value / 10000),-1,255);
14226 if(v > -1)
14227 m->item = v;
14228 m->hasitem = v > -1;
14229 }
14230 break;
14231 }
14232 case MAPDATAREGIONID:
14233 {
14234 370 int region_id = value / 10000;
14235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
370 if (BC::checkBounds(region_id, 0, 9) != SH::_NoError)
14236 break;
14237
14238 370 auto result = decode_mapdata_ref(ri->mapsref);
14239
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.scr)
14240 {
14241
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.type == mapdata_type::CanonicalScreen)
14242 {
14243 370 Regions[result.scr->map].set_region_id(result.screen, region_id);
14244 370 }
14245 else
14246 {
14247 scripting_log_error_with_context("This may only be set for canonical screens");
14248 }
14249 370 }
14250 else
14251 {
14252 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
14253 }
14254 370 break;
14255 }
14256 case MAPDATAHASITEM: SET_MAPDATA_VAR_BYTE(hasitem); break; //b
14257 case MAPDATADOORCOMBOSET: SET_MAPDATA_VAR_INT32(door_combo_set); break; //w
14258 case MAPDATAWARPRETURNC: SET_MAPDATA_VAR_INT32(warpreturnc); break; //w
14259 case MAPDATASTAIRX: SET_MAPDATA_VAR_BYTE(stairx); break; //b
14260 case MAPDATASTAIRY: SET_MAPDATA_VAR_BYTE(stairy); break; //b
14261 case MAPDATAITEMX: SET_MAPDATA_VAR_BYTE(itemx); break; //itemx
14262 case MAPDATAITEMY: SET_MAPDATA_VAR_BYTE(itemy); break; //itemy
14263 case MAPDATACOLOUR: SET_MAPDATA_VAR_INT32(color); break; //w
14264 case MAPDATAENEMYFLAGS: SET_MAPDATA_VAR_BYTE(flags11); break; //b
14265 case MAPDATAEXITDIR: SET_MAPDATA_VAR_BYTE(exitdir); break; //b
14266 case MAPDATAPATTERN: SET_MAPDATA_VAR_BYTE(pattern); break; //b
14267 case MAPDATAWARPARRIVALX: SET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
14268 case MAPDATAWARPARRIVALY: SET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
14269
14270 case MAPDATASIDEWARPINDEX: SET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
14271 case MAPDATAUNDERCOMBO: SET_MAPDATA_VAR_INT32(undercombo); break; //w
14272 case MAPDATAUNDERCSET: SET_MAPDATA_VAR_BYTE(undercset); break; //b
14273 case MAPDATACATCHALL: SET_MAPDATA_VAR_INT32(catchall); break; //W
14274
14275 case MAPDATACSENSITIVE: SET_MAPDATA_VAR_BYTE(csensitive); break; //B
14276 case MAPDATANORESET: SET_MAPDATA_VAR_INT32(noreset); break; //W
14277 case MAPDATANOCARRY: SET_MAPDATA_VAR_INT32(nocarry); break; //W
14278 case MAPDATATIMEDWARPTICS: SET_MAPDATA_VAR_INT32(timedwarptics); break; //W
14279 case MAPDATANEXTMAP: SET_MAPDATA_VAR_BYTE(nextmap); break; //B
14280 case MAPDATANEXTSCREEN: SET_MAPDATA_VAR_BYTE(nextscr); break; //B
14281 case MAPDATAVIEWX: break;//SET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
14282 case MAPDATASCRIPT:
14283 {
14284 auto result = decode_mapdata_ref(ri->mapsref);
14285 if (result.scr)
14286 {
14287 if (result.current())
14288 {
14289 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
14290 {
14291 for (int q=0; q<8; q++)
14292 result.scr->screeninitd[q] = 0;
14293 }
14294
14295 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
14296 }
14297
14298 result.scr->script = vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
14299 }
14300 else
14301 {
14302 Z_scripterrlog("Script attempted to use a mapdata->%s on an invalid pointer\n","Script");
14303 }
14304 break;
14305 }
14306 case MAPDATAVIEWY: break;//SET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
14307 case MAPDATASCREENWIDTH: break;//SET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
14308 case MAPDATASCREENHEIGHT: break;//SET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
14309 case MAPDATAENTRYX: SET_MAPDATA_VAR_BYTE(entry_x); break; //B
14310 case MAPDATAENTRYY: SET_MAPDATA_VAR_BYTE(entry_y); break; //B
14311
14312 //Number of ffcs that are in use (have valid data
14313 case MAPDATANUMFF:
14314 {
14315 break;
14316 }
14317
14318 case MAPDATAINTID:
14319 {
14320 9 int32_t index = (ri->d[rINDEX]/10000);
14321 9 int32_t dindex = ri->d[rINDEX2]/10000;
14322
14323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (BC::checkBounds(dindex, 0, 7) != SH::_NoError)
14324 break;
14325
14326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
14327 9 handle.ffc->initd[dindex] = value;
14328 9 break;
14329 }
14330
14331 case MAPDATASCRIPTENTRY:
14332 {
14333 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
14334 }
14335 break;
14336 case MAPDATASCRIPTOCCUPANCY:
14337 {
14338 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
14339 }
14340 break;
14341 case MAPDATASCRIPTEXIT:
14342 {
14343 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
14344 }
14345 break;
14346
14347 case MAPDATAOCEANSFX:
14348 {
14349 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14350 {
14351 int32_t v = vbound(value/10000, 0, 255);
14352 if(m == hero_scr && m->oceansfx != v)
14353 {
14354 stop_sfx(m->oceansfx);
14355 m->oceansfx = v;
14356 cont_sfx(m->oceansfx);
14357 }
14358 else m->oceansfx = v;
14359 }
14360 break;
14361 }
14362 case MAPDATABOSSSFX: SET_MAPDATA_VAR_BYTE(bosssfx); break; //B
14363 case MAPDATASECRETSFX: SET_MAPDATA_VAR_BYTE(secretsfx); break; //B
14364 case MAPDATAHOLDUPSFX: SET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
14365 case MAPDATASCREENMIDI:
14366 {
14367 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14368 {
14369 m->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
14370 }
14371 break;
14372 }
14373 case MAPDATALENSLAYER: SET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
14374
14375 case MAPDATASCRDATASIZE:
14376 {
14377 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14378 {
14379 int index = get_ref_map_index(ri->mapsref);
14380 if (index < 0) break;
14381
14382 game->scriptDataResize(index, value/10000);
14383 }
14384 break;
14385 }
14386 case MAPDATAGUYCOUNT:
14387 {
14388 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14389 {
14390 int mi = get_mi(ri->mapsref);
14391 if(mi > -1)
14392 {
14393 game->guys[mi] = vbound(value/10000,10,0);
14394 break;
14395 }
14396 }
14397 break;
14398 }
14399 case MAPDATAEXDOOR:
14400 {
14401 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14402 {
14403 int mi = get_mi(ri->mapsref);
14404 if(mi < 0) break;
14405 int dir = SH::read_stack(ri->sp+1) / 10000;
14406 int ind = SH::read_stack(ri->sp+0) / 10000;
14407 if(unsigned(dir) > 3)
14408 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->SetExDoor()'; must be 0-3\n", dir);
14409 else if(unsigned(ind) > 7)
14410 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->SetExDoor()'; must be 0-7\n", ind);
14411 else
14412 set_xdoorstate_mi(mi, dir, ind);
14413 }
14414 break;
14415 }
14416
14417 ///----------------------------------------------------------------------------------------------------//
14418 //dmapdata dmd-> Variables
14419 case DMAPDATAMAP: //byte
14420 {
14421 DMaps[ri->dmapsref].map = ((byte)(value / 10000)) - 1; break;
14422 }
14423 case DMAPDATALEVEL: //word
14424 {
14425 DMaps[ri->dmapsref].level = ((word)(value / 10000)); break;
14426 }
14427 case DMAPDATAOFFSET: //char
14428 {
14429 DMaps[ri->dmapsref].xoff = ((char)(value / 10000)); break;
14430 }
14431 case DMAPDATACOMPASS: //byte
14432 {
14433 DMaps[ri->dmapsref].compass = ((byte)(value / 10000)); break;
14434 }
14435 case DMAPDATAPALETTE: //word
14436 {
14437 20 DMaps[ri->dmapsref].color= ((word)(value / 10000));
14438
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if(ri->dmapsref == cur_dmap)
14439 {
14440 10 loadlvlpal(DMaps[ri->dmapsref].color);
14441 10 currcset = DMaps[ri->dmapsref].color;
14442 10 }
14443 20 break;
14444 }
14445 case DMAPDATAMIDI: //byte
14446 {
14447 DMaps[ri->dmapsref].midi = ((byte)((value / 10000)+MIDIOFFSET_DMAP)); break;
14448 }
14449 case DMAPDATACONTINUE: //byte
14450 {
14451 DMaps[ri->dmapsref].cont = ((byte)(value / 10000)); break;
14452 }
14453 case DMAPDATATYPE: //byte
14454 {
14455 DMaps[ri->dmapsref].type = (((byte)(value / 10000))&dmfTYPE) | (DMaps[ri->dmapsref].type&~dmfTYPE); break;
14456 }
14457 case DMAPSCRIPT: //byte
14458 {
14459 DMaps[ri->dmapsref].script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14460 on_reassign_script_engine_data(ScriptType::DMap, ri->dmapsref);
14461 break;
14462 }
14463 case DMAPDATASIDEVIEW: //byte, treat as bool
14464 {
14465 DMaps[ri->dmapsref].sideview = ((value) ? 1 : 0); break;
14466 }
14467 case DMAPDATAMUISCTRACK: //byte
14468 {
14469 DMaps[ri->dmapsref].tmusictrack= ((byte)(value / 10000)); break;
14470 }
14471 case DMAPDATASUBSCRA:
14472 {
14473 bool changed = DMaps[ri->dmapsref].active_subscreen != ((byte)(value / 10000));
14474 DMaps[ri->dmapsref].active_subscreen= ((byte)(value / 10000));
14475 if(changed&&ri->dmapsref==cur_dmap)
14476 update_subscreens();
14477 break;
14478 }
14479 case DMAPDATASUBSCRP:
14480 {
14481 5120 bool changed = DMaps[ri->dmapsref].passive_subscreen != ((byte)(value / 10000));
14482 5120 DMaps[ri->dmapsref].passive_subscreen= ((byte)(value / 10000));
14483
3/4
✓ Branch 0 taken 5120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 10 times.
5120 if(changed&&ri->dmapsref==cur_dmap)
14484 10 update_subscreens();
14485 5120 break;
14486 }
14487 case DMAPDATASUBSCRO:
14488 {
14489 bool changed = DMaps[ri->dmapsref].overlay_subscreen != ((byte)(value / 10000));
14490 DMaps[ri->dmapsref].overlay_subscreen = ((byte)(value / 10000));
14491 if(changed&&ri->dmapsref==cur_dmap)
14492 update_subscreens();
14493 break;
14494 }
14495 case DMAPDATAFLAGS: //int32_t
14496 {
14497 DMaps[ri->dmapsref].flags = (value / 10000); break;
14498 }
14499 case DMAPDATAMIRRDMAP:
14500 {
14501 DMaps[ri->dmapsref].mirrorDMap = vbound(value / 10000, -1, MAXDMAPS); break;
14502 }
14503 case DMAPDATALOOPSTART:
14504 {
14505 DMaps[ri->dmapsref].tmusic_loop_start = value;
14506 if (ri->dmapsref == cur_dmap)
14507 {
14508 if (FFCore.doing_dmap_enh_music(cur_dmap))
14509 {
14510 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
14511 }
14512 }
14513 break;
14514 }
14515 case DMAPDATALOOPEND:
14516 {
14517 DMaps[ri->dmapsref].tmusic_loop_end = value;
14518 if (ri->dmapsref == cur_dmap)
14519 {
14520 if (FFCore.doing_dmap_enh_music(cur_dmap))
14521 {
14522 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
14523 }
14524 }
14525 break;
14526 }
14527 case DMAPDATAXFADEIN:
14528 {
14529 DMaps[ri->dmapsref].tmusic_xfade_in = (value / 10000);
14530 break;
14531 }
14532 case DMAPDATAXFADEOUT:
14533 {
14534 DMaps[ri->dmapsref].tmusic_xfade_out = (value / 10000);
14535 if (DMaps[cur_dmap].tmusic[0]!=0 && strcmp(DMaps[ri->dmapsref].tmusic, zcmusic->filename) == 0)
14536 {
14537 zcmusic->fadeoutframes = (value / 10000);
14538 }
14539 break;
14540 }
14541 case DMAPDATAINTROSTRINGID:
14542 {
14543 DMaps[ri->dmapsref].intro_string_id = (value / 10000);
14544 break;
14545 }
14546 case MUSICUPDATECOND:
14547 {
14548 FFCore.music_update_cond = vbound(value / 10000, 0, 255);
14549 break;
14550 }
14551 case DMAPDATAASUBSCRIPT: //byte
14552 {
14553 DMaps[ri->dmapsref].active_sub_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14554 on_reassign_script_engine_data(ScriptType::ScriptedActiveSubscreen, ri->dmapsref);
14555 break;
14556 }
14557 case DMAPDATAMAPSCRIPT: //byte
14558 {
14559 3225 DMaps[ri->dmapsref].onmap_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14560 3225 on_reassign_script_engine_data(ScriptType::OnMap, ri->dmapsref);
14561 3225 break;
14562 }
14563 case DMAPDATAPSUBSCRIPT: //byte
14564 {
14565 FFScript::deallocateAllScriptOwned(ScriptType::ScriptedPassiveSubscreen, ri->dmapsref);
14566 word val = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14567 if (FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && ri->dmapsref == cur_dmap && val == DMaps[ri->dmapsref].passive_sub_script)
14568 break;
14569 DMaps[ri->dmapsref].passive_sub_script = val;
14570 if(ri->dmapsref == cur_dmap)
14571 {
14572 FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) = val != 0;
14573 };
14574 break;
14575 }
14576
14577 ///----------------------------------------------------------------------------------------------------//
14578 //messagedata msgd-> Variables
14579
14580
14581 case MESSAGEDATANEXT: //W
14582 {
14583 28 int32_t ID = ri->zmsgref;
14584
14585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if(BC::checkMessage(ID) != SH::_NoError)
14586 break;
14587 else
14588 28 MsgStrings[ID].nextstring = vbound((value/10000), 0, (msg_count-1));
14589 28 break;
14590 }
14591
14592 case MESSAGEDATATILE: //W
14593 {
14594 int32_t ID = ri->zmsgref;
14595
14596 if(BC::checkMessage(ID) != SH::_NoError)
14597 break;
14598 else
14599 MsgStrings[ID].tile = vbound((value/10000), 0, (NEWMAXTILES));
14600 break;
14601 }
14602
14603 case MESSAGEDATACSET: //b
14604 {
14605 int32_t ID = ri->zmsgref;
14606
14607 if(BC::checkMessage(ID) != SH::_NoError)
14608 break;
14609 else
14610 MsgStrings[ID].cset = ((byte)vbound((value/10000), 0, 15));
14611 break;
14612 }
14613 case MESSAGEDATATRANS: //BOOL
14614 {
14615 int32_t ID = ri->zmsgref;
14616
14617 if(BC::checkMessage(ID) != SH::_NoError)
14618 break;
14619 else
14620 (MsgStrings[ID].trans) = ((value)?true:false);
14621 break;
14622 }
14623 case MESSAGEDATAFONT: //B
14624 {
14625 int32_t ID = ri->zmsgref;
14626
14627 if(BC::checkMessage(ID) != SH::_NoError)
14628 break;
14629 else
14630 MsgStrings[ID].font = ((byte)vbound((value/10000), 0, 255));
14631 break;
14632 }
14633 case MESSAGEDATAX: //SHORT
14634 {
14635 24 int32_t ID = ri->zmsgref;
14636
14637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14638 break;
14639 else
14640 24 MsgStrings[ID].x = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
14641 24 break;
14642 }
14643 case MESSAGEDATAY: //SHORT
14644 {
14645 24 int32_t ID = ri->zmsgref;
14646
14647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14648 break;
14649 else
14650 24 MsgStrings[ID].y = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
14651 24 break;
14652 }
14653 case MESSAGEDATAW: //UNSIGNED SHORT
14654 {
14655 int32_t ID = ri->zmsgref;
14656
14657 if(BC::checkMessage(ID) != SH::_NoError)
14658 break;
14659 else
14660 MsgStrings[ID].w = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
14661 break;
14662 }
14663 case MESSAGEDATAH: //UNSIGNED SHORT
14664 {
14665 int32_t ID = ri->zmsgref;
14666
14667 if(BC::checkMessage(ID) != SH::_NoError)
14668 break;
14669 else
14670 MsgStrings[ID].h = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
14671 break;
14672 }
14673 case MESSAGEDATASFX: //BYTE
14674 {
14675 24 int32_t ID = ri->zmsgref;
14676
14677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14678 break;
14679 else
14680 24 MsgStrings[ID].sfx = ((byte)vbound((value/10000), 0, 255));
14681 24 break;
14682 }
14683 case MESSAGEDATALISTPOS: //WORD
14684 {
14685 int32_t ID = ri->zmsgref;
14686
14687 if(BC::checkMessage(ID) != SH::_NoError)
14688 break;
14689 else
14690 MsgStrings[ID].listpos = vbound((value/10000), 1, (msg_count-1));
14691 break;
14692 }
14693 case MESSAGEDATAVSPACE: //BYTE
14694 {
14695 int32_t ID = ri->zmsgref;
14696
14697 if(BC::checkMessage(ID) != SH::_NoError)
14698 break;
14699 else
14700 MsgStrings[ID].vspace = ((byte)vbound((value/10000), 0, 255));
14701 break;
14702 }
14703 case MESSAGEDATAHSPACE: //BYTE
14704 {
14705 int32_t ID = ri->zmsgref;
14706
14707 if(BC::checkMessage(ID) != SH::_NoError)
14708 break;
14709 else
14710 MsgStrings[ID].hspace = ((byte)vbound((value/10000), 0, 255));
14711 break;
14712 }
14713 case MESSAGEDATAFLAGS: //BYTE
14714 {
14715 int32_t ID = ri->zmsgref;
14716
14717 if(BC::checkMessage(ID) != SH::_NoError)
14718 break;
14719 else
14720 MsgStrings[ID].stringflags = ((byte)vbound((value/10000), 0, 255));
14721 break;
14722 }
14723 case MESSAGEDATAPORTTILE: //INT
14724 {
14725 int32_t ID = ri->zmsgref;
14726
14727 if(BC::checkMessage(ID) != SH::_NoError)
14728 break;
14729 else
14730 MsgStrings[ID].portrait_tile = vbound((value/10000), 0, (NEWMAXTILES));
14731 break;
14732 }
14733 case MESSAGEDATAPORTCSET: //BYTE
14734 {
14735 int32_t ID = ri->zmsgref;
14736
14737 if(BC::checkMessage(ID) != SH::_NoError)
14738 break;
14739 else
14740 MsgStrings[ID].portrait_cset = ((byte)vbound((value/10000), 0, 15));
14741 break;
14742 }
14743 case MESSAGEDATAPORTX: //BYTE
14744 {
14745 int32_t ID = ri->zmsgref;
14746
14747 if(BC::checkMessage(ID) != SH::_NoError)
14748 break;
14749 else
14750 MsgStrings[ID].portrait_x = ((byte)vbound((value/10000), 0, 255));
14751 break;
14752 }
14753 case MESSAGEDATAPORTY: //BYTE
14754 {
14755 int32_t ID = ri->zmsgref;
14756
14757 if(BC::checkMessage(ID) != SH::_NoError)
14758 break;
14759 else
14760 MsgStrings[ID].portrait_y = ((byte)vbound((value/10000), 0, 255));
14761 break;
14762 }
14763 case MESSAGEDATAPORTWID: //BYTE
14764 {
14765 int32_t ID = ri->zmsgref;
14766
14767 if(BC::checkMessage(ID) != SH::_NoError)
14768 break;
14769 else
14770 MsgStrings[ID].portrait_tw = ((byte)vbound((value/10000), 0, 16));
14771 break;
14772 }
14773 case MESSAGEDATAPORTHEI: //BYTE
14774 {
14775 int32_t ID = ri->zmsgref;
14776
14777 if(BC::checkMessage(ID) != SH::_NoError)
14778 break;
14779 else
14780 MsgStrings[ID].portrait_th = ((byte)vbound((value/10000), 0, 14));
14781 break;
14782 }
14783
14784 ///----------------------------------------------------------------------------------------------------//
14785 //combodata cd-> Setter Variables
14786 //newcombo
14787 #define SET_COMBO_VAR_INT(member) \
14788 { \
14789 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14790 { \
14791 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14792 } \
14793 else \
14794 { \
14795 screen_combo_modify_pre(ri->combosref); \
14796 combobuf[ri->combosref].member = vbound((value / 10000),0,214747); \
14797 screen_combo_modify_post(ri->combosref); \
14798 \
14799 } \
14800 } \
14801
14802 #define SET_COMBO_VAR_DWORD(member) \
14803 { \
14804 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14805 { \
14806 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14807 } \
14808 else \
14809 { \
14810 screen_combo_modify_pre(ri->combosref); \
14811 combobuf[ri->combosref].member = vbound((value / 10000),0,32767); \
14812 screen_combo_modify_post(ri->combosref); \
14813 } \
14814 } \
14815
14816 #define SET_COMBO_VAR_BYTE(member) \
14817 { \
14818 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14819 { \
14820 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14821 } \
14822 else \
14823 { \
14824 screen_combo_modify_pre(ri->combosref); \
14825 combobuf[ri->combosref].member = vbound((value / 10000),0,255); \
14826 screen_combo_modify_post(ri->combosref); \
14827 } \
14828 } \
14829
14830 #define SET_COMBO_FLAG(member) \
14831 { \
14832 int32_t flag = (value/10000); \
14833 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14834 { \
14835 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14836 } \
14837 else \
14838 { \
14839 if ( flag != 0 ) \
14840 { \
14841 combobuf[ri->combosref].member|=flag; \
14842 } \
14843 else combobuf[ri->combosref].member|= ~flag; \
14844 } \
14845 } \
14846
14847 //comboclass
14848 #define SET_COMBOCLASS_VAR_INT(member) \
14849 { \
14850 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14851 { \
14852 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14853 } \
14854 else \
14855 { \
14856 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,214747); \
14857 } \
14858 } \
14859
14860 #define SET_COMBOCLASS_VAR_DWORD(member) \
14861 { \
14862 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14863 { \
14864 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14865 } \
14866 else \
14867 { \
14868 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,32767); \
14869 } \
14870 } \
14871
14872 #define SET_COMBOCLASS_VAR_BYTE(member) \
14873 { \
14874 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14875 { \
14876 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14877 } \
14878 else \
14879 { \
14880 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,255); \
14881 } \
14882 } \
14883
14884 #define SET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
14885 { \
14886 int32_t indx = ri->d[rINDEX] / 10000; \
14887 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14888 { \
14889 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14890 } \
14891 else if ( indx < 0 || indx > indexbound ) \
14892 { \
14893 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
14894 } \
14895 else \
14896 { \
14897 combo_class_buf[combobuf[ri->combosref].type].member[indx] = vbound((value / 10000),0,255); \
14898 } \
14899 }
14900
14901 #define SET_COMBOCLASS_FLAG(member, str) \
14902 { \
14903 int32_t flag = (value/10000); \
14904 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14905 { \
14906 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14907 } \
14908 else \
14909 { \
14910 if ( flag != 0 ) \
14911 { \
14912 combo_class_buf[combobuf[ri->combosref].type].member|=flag; \
14913 } \
14914 else combo_class_buf[combobuf[ri->combosref].type].member|= ~flag; \
14915 } \
14916 } \
14917
14918 //NEWCOMBO STRUCT
14919 case COMBODTILE: SET_COMBO_VAR_INT(tile); break; //word
14920 case COMBODOTILE:
14921 {
14922 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14923 {
14924 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14925 }
14926 else
14927 {
14928 newcombo& cdata = combobuf[ri->combosref];
14929 cdata.o_tile = vbound((value / 10000),0,NEWMAXTILES);
14930 if(get_qr(qr_NEW_COMBO_ANIMATION))
14931 {
14932 cdata.tile = cdata.o_tile + ((1+cdata.skipanim)*cdata.cur_frame);
14933 if(int32_t rowoffset = TILEROW(cdata.tile)-TILEROW(cdata.o_tile))
14934 {
14935 cdata.tile += cdata.skipanimy * rowoffset * TILES_PER_ROW;
14936 }
14937 combo_caches::drawing.refresh(ri->combosref);
14938 }
14939 }
14940 break;
14941 }
14942 case COMBODFRAME: SET_COMBO_VAR_BYTE(cur_frame); break; //char
14943 case COMBODACLK: SET_COMBO_VAR_BYTE(aclk); break; //char
14944 case COMBODATASCRIPT: SET_COMBO_VAR_DWORD(script); break; //word
14945 case COMBODASPEED: SET_COMBO_VAR_BYTE(speed); break; //char
14946 case COMBODFLIP: SET_COMBO_VAR_BYTE(flip); break; //char
14947 case COMBODWALK:
14948 {
14949 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14950 {
14951 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14952 }
14953 else
14954 {
14955 combobuf[ri->combosref].walk &= ~0x0F;
14956 combobuf[ri->combosref].walk |= (value / 10000)&0x0F;
14957 }
14958 break;
14959 }
14960 case COMBODEFFECT:
14961 {
14962 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14963 {
14964 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14965 }
14966 else
14967 {
14968 combobuf[ri->combosref].walk &= ~0xF0;
14969 combobuf[ri->combosref].walk |= ((value / 10000)&0x0F)<<4;
14970 }
14971 break;
14972 }
14973 case COMBODTYPE:
14974 {
14975 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14976 {
14977 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14978 }
14979 else
14980 {
14981 screen_combo_modify_pre(ri->combosref);
14982 combobuf[ri->combosref].type = vbound((value / 10000),0,255);
14983 screen_combo_modify_post(ri->combosref);
14984 }
14985 break;
14986 }
14987 case COMBODCSET:
14988 {
14989 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14990 {
14991 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14992 }
14993 else
14994 {
14995 screen_combo_modify_pre(ri->combosref);
14996 int8_t v = vbound(value, -8, 7);
14997 combobuf[ri->combosref].csets &= ~0xF;
14998 combobuf[ri->combosref].csets |= v;
14999 screen_combo_modify_post(ri->combosref);
15000 }
15001 break;
15002 }
15003 case COMBODCSET2FLAGS:
15004 {
15005 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15006 {
15007 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15008 }
15009 else
15010 {
15011 screen_combo_modify_pre(ri->combosref);
15012 combobuf[ri->combosref].csets &= 0xF;
15013 combobuf[ri->combosref].csets |= (value&0xF)<<4;
15014 screen_combo_modify_post(ri->combosref);
15015 }
15016 break;
15017 }
15018 case COMBODFOO: break; //W
15019 case COMBODFRAMES: SET_COMBO_VAR_BYTE(frames); break; //C
15020 case COMBODNEXTD: SET_COMBO_VAR_INT(nextcombo); break; //W
15021 case COMBODNEXTC: SET_COMBO_VAR_BYTE(nextcset); break; //C
15022 case COMBODFLAG: SET_COMBO_VAR_BYTE(flag); break; //C
15023 case COMBODSKIPANIM: SET_COMBO_VAR_BYTE(skipanim); break; //C
15024 case COMBODNEXTTIMER: SET_COMBO_VAR_DWORD(nexttimer); break; //W
15025 case COMBODAKIMANIMY: SET_COMBO_VAR_BYTE(skipanimy); break; //C
15026 case COMBODANIMFLAGS: SET_COMBO_VAR_BYTE(animflags); break; //C
15027 case COMBODUSRFLAGS: SET_COMBO_VAR_INT(usrflags); break; //LONG
15028 case COMBODTRIGGERITEM:
15029 {
15030 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15031 {
15032 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15033 }
15034 else if(auto* trig = get_first_combo_trigger())
15035 trig->triggeritem = vbound(value/10000,0,255);
15036 break;
15037 }
15038 case COMBODTRIGGERTIMER:
15039 {
15040 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15041 {
15042 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15043 }
15044 else
15045 {
15046 screen_combo_modify_pre(ri->combosref);
15047 if(auto* trig = get_first_combo_trigger())
15048 trig->trigtimer = vbound(value/10000,0,65535);
15049 screen_combo_modify_post(ri->combosref);
15050 }
15051 break;
15052 }
15053 case COMBODTRIGGERSFX:
15054 {
15055 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15056 {
15057 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15058 }
15059 else if(auto* trig = get_first_combo_trigger())
15060 trig->trigsfx = vbound(value/10000,0,255);
15061 break;
15062 }
15063 case COMBODTRIGGERCHANGECMB:
15064 {
15065 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15066 {
15067 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15068 }
15069 else if(auto* trig = get_first_combo_trigger())
15070 trig->trigchange = vbound(value/10000,-65535,65535);
15071 break;
15072 }
15073 case COMBODTRIGGERPROX:
15074 {
15075 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15076 {
15077 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15078 }
15079 else if(auto* trig = get_first_combo_trigger())
15080 trig->trigprox = vbound(value/10000,0,65535);
15081 break;
15082 }
15083 case COMBODTRIGGERLIGHTBEAM:
15084 {
15085 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15086 {
15087 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15088 }
15089 else if(auto* trig = get_first_combo_trigger())
15090 trig->triglbeam = vbound(value/10000,0,32);
15091 break;
15092 }
15093 case COMBODTRIGGERCTR:
15094 {
15095 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15096 {
15097 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15098 }
15099 else if(auto* trig = get_first_combo_trigger())
15100 trig->trigctr = vbound(value/10000, sscMIN, MAX_COUNTERS-1);
15101 break;
15102 }
15103 case COMBODTRIGGERCTRAMNT:
15104 {
15105 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15106 {
15107 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15108 }
15109 else if(auto* trig = get_first_combo_trigger())
15110 trig->trigctramnt = vbound(value/10000, -65535, 65535);
15111 break;
15112 }
15113
15114 case COMBODTRIGGERCOOLDOWN:
15115 {
15116 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15117 {
15118 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15119 }
15120 else if(auto* trig = get_first_combo_trigger())
15121 trig->trigcooldown = vbound(value/10000, 0, 255);
15122 break;
15123 }
15124 case COMBODTRIGGERCOPYCAT:
15125 {
15126 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15127 {
15128 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15129 }
15130 else if(auto* trig = get_first_combo_trigger())
15131 trig->trigcopycat = vbound(value/10000, 0, 255);
15132 break;
15133 }
15134 case COMBODTRIGITEMPICKUP:
15135 {
15136 const int32_t allowed_pflags = ipHOLDUP | ipTIMER | ipSECRETS | ipCANGRAB;
15137 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15138 {
15139 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15140 }
15141 else if(auto* trig = get_first_combo_trigger())
15142 trig->spawnip = (value/10000)&allowed_pflags;
15143 break;
15144 }
15145 case COMBODTRIGEXSTATE:
15146 {
15147 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15148 {
15149 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15150 }
15151 else if(auto* trig = get_first_combo_trigger())
15152 trig->exstate = vbound(value/10000, -1, 31);
15153 break;
15154 }
15155 case COMBODTRIGEXDOORDIR:
15156 {
15157 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15158 {
15159 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15160 }
15161 else if(auto* trig = get_first_combo_trigger())
15162 trig->exdoor_dir = vbound(value/10000, -1, 3);
15163 break;
15164 }
15165 case COMBODTRIGEXDOORIND:
15166 {
15167 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15168 {
15169 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15170 }
15171 else if(auto* trig = get_first_combo_trigger())
15172 trig->exdoor_ind = vbound(value/10000, 0, 7);
15173 break;
15174 }
15175 case COMBODTRIGSPAWNENEMY:
15176 {
15177 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15178 {
15179 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15180 }
15181 else if(auto* trig = get_first_combo_trigger())
15182 trig->spawnenemy = vbound(value/10000, 0, 511);
15183 break;
15184 }
15185 case COMBODTRIGSPAWNITEM:
15186 {
15187 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15188 {
15189 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15190 }
15191 else if(auto* trig = get_first_combo_trigger())
15192 trig->spawnitem = vbound(value/10000, -255, 255);
15193 break;
15194 }
15195 case COMBODTRIGCSETCHANGE:
15196 {
15197 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15198 {
15199 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15200 }
15201 else if(auto* trig = get_first_combo_trigger())
15202 trig->trigcschange = vbound(value/10000, -15, 15);
15203 break;
15204 }
15205 case COMBODTRIGLITEMS:
15206 {
15207 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15208 {
15209 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15210 }
15211 else if(auto* trig = get_first_combo_trigger())
15212 trig->trig_levelitems = (value/10000)&liALL;
15213 break;
15214 }
15215 case COMBODTRIGDMAPLVL:
15216 {
15217 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15218 {
15219 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15220 }
15221 else if(auto* trig = get_first_combo_trigger())
15222 trig->trigdmlevel = vbound(value/10000, -1, MAXLEVELS-1);
15223 break;
15224 }
15225 case COMBODTRIGTINTR:
15226 {
15227 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15228 {
15229 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15230 }
15231 else if(auto* trig = get_first_combo_trigger())
15232 trig->trigtint[0] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15233 break;
15234 }
15235 case COMBODTRIGTINTG:
15236 {
15237 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15238 {
15239 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15240 }
15241 else if(auto* trig = get_first_combo_trigger())
15242 trig->trigtint[1] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15243 break;
15244 }
15245 case COMBODTRIGTINTB:
15246 {
15247 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15248 {
15249 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15250 }
15251 else if(auto* trig = get_first_combo_trigger())
15252 trig->trigtint[2] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15253 break;
15254 }
15255 case COMBODTRIGLVLPAL:
15256 {
15257 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15258 {
15259 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15260 }
15261 else if(auto* trig = get_first_combo_trigger())
15262 trig->triglvlpalette = vbound(value/10000, -1, 512);
15263 break;
15264 }
15265 case COMBODTRIGBOSSPAL:
15266 {
15267 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15268 {
15269 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15270 }
15271 else if(auto* trig = get_first_combo_trigger())
15272 trig->trigbosspalette = vbound(value/10000, -1, 29);
15273 break;
15274 }
15275 case COMBODTRIGQUAKETIME:
15276 {
15277 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15278 {
15279 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15280 }
15281 else if(auto* trig = get_first_combo_trigger())
15282 trig->trigquaketime = zc_max(value/10000, -1);
15283 break;
15284 }
15285 case COMBODTRIGWAVYTIME:
15286 {
15287 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15288 {
15289 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15290 }
15291 else if(auto* trig = get_first_combo_trigger())
15292 trig->trigwavytime = zc_max(value/10000, -1);
15293 break;
15294 }
15295 case COMBODTRIGSWORDJINX:
15296 {
15297 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15298 {
15299 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15300 }
15301 else if(auto* trig = get_first_combo_trigger())
15302 trig->trig_swjinxtime = zc_max(value/10000, -2);
15303 break;
15304 }
15305 case COMBODTRIGITEMJINX:
15306 {
15307 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15308 {
15309 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15310 }
15311 else if(auto* trig = get_first_combo_trigger())
15312 trig->trig_itmjinxtime = zc_max(value/10000, -2);
15313 break;
15314 }
15315 case COMBODTRIGSHIELDJINX:
15316 {
15317 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
15318 {
15319 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15320 }
15321 else if(auto* trig = get_first_combo_trigger())
15322 trig->trig_shieldjinxtime = zc_max(value / 10000, -2);
15323 break;
15324 }
15325 case COMBODTRIGSTUN:
15326 {
15327 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15328 {
15329 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15330 }
15331 else if(auto* trig = get_first_combo_trigger())
15332 trig->trig_stuntime = zc_max(value/10000, -2);
15333 break;
15334 }
15335 case COMBODTRIGBUNNY:
15336 {
15337 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15338 {
15339 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15340 }
15341 else if(auto* trig = get_first_combo_trigger())
15342 trig->trig_bunnytime = zc_max(value/10000, -2);
15343 break;
15344 }
15345 case COMBODTRIGPUSHTIME:
15346 {
15347 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15348 {
15349 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15350 }
15351 else if(auto* trig = get_first_combo_trigger())
15352 trig->trig_pushtime = vbound(value/10000, 0, 255);
15353 break;
15354 }
15355 case COMBODLIFTGFXCOMBO:
15356 {
15357 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15358 {
15359 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15360 }
15361 else combobuf[ri->combosref].liftcmb = vbound(value/10000, 0, MAXCOMBOS);
15362 break;
15363 }
15364 case COMBODLIFTGFXCCSET:
15365 {
15366 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15367 {
15368 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15369 }
15370 else combobuf[ri->combosref].liftcs = vbound(value/10000, 0, 13);
15371 break;
15372 }
15373 case COMBODLIFTUNDERCMB:
15374 {
15375 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15376 {
15377 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15378 }
15379 else combobuf[ri->combosref].liftundercmb = vbound(value/10000, 0, MAXCOMBOS);
15380 break;
15381 }
15382 case COMBODLIFTUNDERCS:
15383 {
15384 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15385 {
15386 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15387 }
15388 else combobuf[ri->combosref].liftundercs = vbound(value/10000, 0, 13);
15389 break;
15390 }
15391 case COMBODLIFTDAMAGE:
15392 {
15393 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15394 {
15395 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15396 }
15397 else combobuf[ri->combosref].liftdmg = vbound(value/10000, 0, 255);
15398 break;
15399 }
15400 case COMBODLIFTLEVEL:
15401 {
15402 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15403 {
15404 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15405 }
15406 else combobuf[ri->combosref].liftlvl = vbound(value/10000, 0, 255);
15407 break;
15408 }
15409 case COMBODLIFTITEM:
15410 {
15411 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15412 {
15413 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15414 }
15415 else combobuf[ri->combosref].liftitm = vbound(value/10000, 0, 255);
15416 break;
15417 }
15418 case COMBODLIFTGFXTYPE:
15419 {
15420 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15421 {
15422 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15423 }
15424 else combobuf[ri->combosref].liftgfx = vbound(value/10000, 0, 2);
15425 break;
15426 }
15427 case COMBODLIFTGFXSPRITE:
15428 {
15429 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15430 {
15431 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15432 }
15433 else combobuf[ri->combosref].liftsprite = vbound(value/10000, 0, 255);
15434 break;
15435 }
15436 case COMBODLIFTSFX:
15437 {
15438 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15439 {
15440 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15441 }
15442 else combobuf[ri->combosref].liftsfx = vbound(value/10000, 0, 255);
15443 break;
15444 }
15445 case COMBODLIFTBREAKSPRITE:
15446 {
15447 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15448 {
15449 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15450 }
15451 else combobuf[ri->combosref].liftbreaksprite = vbound(value/10000, -4, 255);
15452 break;
15453 }
15454 case COMBODLIFTBREAKSFX:
15455 {
15456 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15457 {
15458 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15459 }
15460 else combobuf[ri->combosref].liftbreaksfx = vbound(value/10000, 0, 255);
15461 break;
15462 }
15463 case COMBODLIFTHEIGHT:
15464 {
15465 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15466 {
15467 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15468 }
15469 else combobuf[ri->combosref].lifthei = vbound(value/10000, 0, 255);
15470 break;
15471 }
15472 case COMBODLIFTTIME:
15473 {
15474 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15475 {
15476 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15477 }
15478 else combobuf[ri->combosref].lifttime = vbound(value/10000, 0, 255);
15479 break;
15480 }
15481 case COMBODLIFTLIGHTRAD:
15482 {
15483 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15484 {
15485 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15486 }
15487 else combobuf[ri->combosref].lift_weap_data.light_rads[WPNSPR_BASE] = vbound(value/10000, 0, 255);
15488 break;
15489 }
15490 case COMBODLIFTLIGHTSHAPE:
15491 {
15492 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15493 {
15494 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15495 }
15496 else combobuf[ri->combosref].lift_weap_data.glow_shape = vbound(value/10000, 0, 2);
15497 break;
15498 }
15499 case COMBODLIFTWEAPONITEM:
15500 {
15501 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15502 {
15503 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15504 }
15505 else combobuf[ri->combosref].lift_parent_item = vbound(value/10000, 0, 255);
15506 break;
15507 }
15508 case COMBODTRIGGERLSTATE:
15509 {
15510 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15511 {
15512 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15513 }
15514 else if(auto* trig = get_first_combo_trigger())
15515 trig->trig_lstate = vbound(value/10000, 0, 31);
15516 break;
15517 }
15518 case COMBODTRIGGERGSTATE:
15519 {
15520 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15521 {
15522 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15523 }
15524 else if(auto* trig = get_first_combo_trigger())
15525 trig->trig_gstate = vbound(value/10000, 0, 255);
15526 break;
15527 }
15528 case COMBODTRIGGERGROUP:
15529 {
15530 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15531 {
15532 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15533 }
15534 else if(auto* trig = get_first_combo_trigger())
15535 trig->trig_group = vbound(value/10000, 0, 255);
15536 break;
15537 }
15538 case COMBODTRIGGERGROUPVAL:
15539 {
15540 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15541 {
15542 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15543 }
15544 else if(auto* trig = get_first_combo_trigger())
15545 trig->trig_group_val = vbound(value/10000, 0, 65535);
15546 break;
15547 }
15548 case COMBODTRIGGERGTIMER:
15549 {
15550 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15551 {
15552 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15553 }
15554 else if(auto* trig = get_first_combo_trigger())
15555 trig->trig_statetime = vbound(value/10000, 0, 214748);
15556 break;
15557 }
15558 case COMBODTRIGGERGENSCRIPT:
15559 {
15560 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15561 {
15562 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15563 }
15564 else if(auto* trig = get_first_combo_trigger())
15565 trig->trig_genscr = vbound(value/10000, 0, 65535);
15566 break;
15567 }
15568 case COMBODTRIGGERLEVEL:
15569 {
15570 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15571 {
15572 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15573 }
15574 else if(auto* trig = get_first_combo_trigger())
15575 trig->triggerlevel = vbound(value/10000, 0, 214747);
15576 break;
15577 }
15578 case COMBODNUMTRIGGERS:
15579 {
15580 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15581 {
15582 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15583 }
15584 else
15585 combobuf[ri->combosref].triggers.resize(vbound(value / 10000, 0, MAX_COMBO_TRIGGERS));
15586 break;
15587 }
15588 case COMBODONLYGEN:
15589 {
15590 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15591 {
15592 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15593 }
15594 else
15595 combobuf[ri->combosref].only_gentrig = value != 0 ? 1 : 0;
15596 break;
15597 }
15598 case COMBOD_Z_HEIGHT:
15599 {
15600 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15601 {
15602 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15603 }
15604 else
15605 combobuf[ri->combosref].z_height = zslongToFix(value);
15606 break;
15607 }
15608 case COMBOD_Z_STEP_HEIGHT:
15609 {
15610 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15611 {
15612 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15613 }
15614 else
15615 combobuf[ri->combosref].z_step_height = zslongToFix(zc_max(0,value));
15616 break;
15617 }
15618
15619
15620
15621
15622 //COMBOCLASS STRUCT
15623 //case COMBODNAME: //CHAR[64], STRING
15624 case COMBODBLOCKNPC: SET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
15625 case COMBODBLOCKHOLE: SET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
15626 case COMBODBLOCKTRIG: SET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
15627 // Note: not used?
15628 case COMBODBLOCKWEAPON: SET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
15629 case COMBODCONVXSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
15630 case COMBODCONVYSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
15631 case COMBODSPAWNNPC: SET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
15632 case COMBODSPAWNNPCWHEN: SET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
15633 case COMBODSPAWNNPCCHANGE: SET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
15634 case COMBODDIRCHANGETYPE: SET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
15635 case COMBODDISTANCECHANGETILES: SET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
15636 case COMBODDIVEITEM: SET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
15637 case COMBODDOCK: SET_COMBOCLASS_VAR_BYTE(dock); break; //C
15638 case COMBODFAIRY: SET_COMBOCLASS_VAR_BYTE(fairy); break; //C
15639 case COMBODFFATTRCHANGE: SET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
15640 case COMBODFOORDECOTILE: SET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
15641 case COMBODFOORDECOTYPE: SET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
15642 case COMBODHOOKSHOTPOINT: SET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
15643 case COMBODLADDERPASS: SET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
15644 case COMBODLOCKBLOCK: SET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
15645 case COMBODLOCKBLOCKCHANGE: SET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
15646 case COMBODMAGICMIRROR: SET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
15647 case COMBODMODHPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
15648 case COMBODMODHPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
15649 case COMBODMODHPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
15650 case COMBODNMODMPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
15651 case COMBODMODMPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
15652 case COMBODMODMPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
15653 case COMBODNOPUSHBLOCK: SET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
15654 case COMBODOVERHEAD: SET_COMBOCLASS_VAR_BYTE(overhead); break; //C
15655 case COMBODPLACENPC: SET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
15656 case COMBODPUSHDIR: SET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
15657 case COMBODPUSHWAIT: SET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
15658 case COMBODPUSHHEAVY: SET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
15659 case COMBODPUSHED: SET_COMBOCLASS_VAR_BYTE(pushed); break; //C
15660 case COMBODRAFT: SET_COMBOCLASS_VAR_BYTE(raft); break; //C
15661 case COMBODRESETROOM: SET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
15662 case COMBODSAVEPOINTTYPE: SET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
15663 case COMBODSCREENFREEZETYPE: SET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
15664 case COMBODSECRETCOMBO: SET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
15665 case COMBODSINGULAR: SET_COMBOCLASS_VAR_BYTE(singular); break; //C
15666 case COMBODSLOWWALK: SET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
15667 case COMBODSTATUETYPE: SET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
15668 case COMBODSTEPTYPE: SET_COMBOCLASS_VAR_BYTE(step_type); break; //C
15669 case COMBODSTEPCHANGEINTO: SET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
15670 case COMBODSTRIKEWEAPONS: SET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
15671 case COMBODSTRIKEREMNANTS: SET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
15672 case COMBODSTRIKEREMNANTSTYPE: SET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
15673 case COMBODSTRIKECHANGE: SET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
15674 case COMBODSTRIKEITEM: SET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
15675 case COMBODTOUCHITEM: SET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
15676 case COMBODTOUCHSTAIRS: SET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
15677 case COMBODTRIGGERTYPE: SET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
15678 case COMBODTRIGGERSENS: SET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
15679 case COMBODWARPTYPE: SET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
15680 case COMBODWARPSENS: SET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
15681 case COMBODWARPDIRECT: SET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
15682 case COMBODWARPLOCATION: SET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
15683 case COMBODWATER: SET_COMBOCLASS_VAR_BYTE(water); break; //C
15684 case COMBODWHISTLE: SET_COMBOCLASS_VAR_BYTE(whistle); break; //C
15685 case COMBODWINGAME: SET_COMBOCLASS_VAR_BYTE(win_game); break; //C
15686 case COMBODBLOCKWPNLEVEL: SET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
15687
15688
15689
15690 ///----------------------------------------------------------------------------------------------------//
15691 case CMBTRIGWPNLEVEL:
15692 {
15693 if(auto* trig = get_combo_trigger(ri->combotrigref))
15694 {
15695 trig->triggerlevel = vbound(value/10000, 0, 214748);
15696 }
15697 break;
15698 }
15699 case CMBTRIGREQITEM:
15700 {
15701 if(auto* trig = get_combo_trigger(ri->combotrigref))
15702 {
15703 trig->triggeritem = vbound(value/10000, 0, MAXITEMS-1);
15704 }
15705 break;
15706 }
15707 case CMBTRIGTIMER:
15708 {
15709 if(auto* trig = get_combo_trigger(ri->combotrigref))
15710 {
15711 trig->trigtimer = vbound(value/10000, 0, 65535);
15712 }
15713 break;
15714 }
15715 case CMBTRIGSFX:
15716 {
15717 if(auto* trig = get_combo_trigger(ri->combotrigref))
15718 {
15719 trig->trigsfx = vbound(value/10000, 0, 255);
15720 }
15721 break;
15722 }
15723 case CMBTRIGCHANGECMB:
15724 {
15725 if(auto* trig = get_combo_trigger(ri->combotrigref))
15726 {
15727 trig->trigchange = value/10000;
15728 }
15729 break;
15730 }
15731 case CMBTRIGCSETCHANGE:
15732 {
15733 if(auto* trig = get_combo_trigger(ri->combotrigref))
15734 {
15735 trig->trigcschange = vbound(value/10000, -128, 127);
15736 }
15737 break;
15738 }
15739 case CMBTRIGPROX:
15740 {
15741 if(auto* trig = get_combo_trigger(ri->combotrigref))
15742 {
15743 trig->trigprox = vbound(value/10000, 0, 65535);
15744 }
15745 break;
15746 }
15747 case CMBTRIGLIGHTBEAM:
15748 {
15749 if(auto* trig = get_combo_trigger(ri->combotrigref))
15750 {
15751 trig->triglbeam = vbound(value/10000,0,32);
15752 }
15753 break;
15754 }
15755 case CMBTRIGCTR:
15756 {
15757 if(auto* trig = get_combo_trigger(ri->combotrigref))
15758 {
15759 trig->trigctr = vbound(value/10000, sscMIN, MAX_COUNTERS-1);
15760 }
15761 break;
15762 }
15763 case CMBTRIGCTRAMNT:
15764 {
15765 if(auto* trig = get_combo_trigger(ri->combotrigref))
15766 {
15767 trig->trigctramnt = vbound(value/10000, -65535, 65535);
15768 }
15769 break;
15770 }
15771 case CMBTRIGCOOLDOWN:
15772 {
15773 if(auto* trig = get_combo_trigger(ri->combotrigref))
15774 {
15775 trig->trigcooldown = vbound(value/10000, 0, 255);
15776 }
15777 break;
15778 }
15779 case CMBTRIGCOPYCAT:
15780 {
15781 if(auto* trig = get_combo_trigger(ri->combotrigref))
15782 {
15783 trig->trigcopycat = vbound(value/10000, 0, 255);
15784 }
15785 break;
15786 }
15787 case CMBTRIGITEMPICKUP:
15788 {
15789 const int32_t allowed_pflags = ipHOLDUP | ipTIMER | ipSECRETS | ipCANGRAB;
15790 if(auto* trig = get_combo_trigger(ri->combotrigref))
15791 {
15792 trig->spawnip = (value/10000)&allowed_pflags;
15793 }
15794 break;
15795 }
15796 case CMBTRIGEXSTATE:
15797 {
15798 if(auto* trig = get_combo_trigger(ri->combotrigref))
15799 {
15800 trig->exstate = vbound(value/10000, -1, 31);
15801 }
15802 break;
15803 }
15804 case CMBTRIGEXDOORDIR:
15805 {
15806 if(auto* trig = get_combo_trigger(ri->combotrigref))
15807 {
15808 trig->exdoor_dir = vbound(value/10000, -1, 3);
15809 }
15810 break;
15811 }
15812 case CMBTRIGEXDOORIND:
15813 {
15814 if(auto* trig = get_combo_trigger(ri->combotrigref))
15815 {
15816 trig->exdoor_ind = vbound(value/10000, 0, 7);
15817 }
15818 break;
15819 }
15820 case CMBTRIGSPAWNENEMY:
15821 {
15822 if(auto* trig = get_combo_trigger(ri->combotrigref))
15823 {
15824 trig->spawnenemy = vbound(value/10000, 0, 511);
15825 }
15826 break;
15827 }
15828 case CMBTRIGSPAWNITEM:
15829 {
15830 if(auto* trig = get_combo_trigger(ri->combotrigref))
15831 {
15832 trig->spawnitem = vbound(value/10000, -255, 255);
15833 }
15834 break;
15835 }
15836 case CMBTRIGLSTATE:
15837 {
15838 if(auto* trig = get_combo_trigger(ri->combotrigref))
15839 {
15840 trig->trig_lstate = vbound(value/10000, 0, 31);
15841 }
15842 break;
15843 }
15844 case CMBTRIGGSTATE:
15845 {
15846 if(auto* trig = get_combo_trigger(ri->combotrigref))
15847 {
15848 trig->trig_gstate = vbound(value/10000, 0, 255);
15849 }
15850 break;
15851 }
15852 case CMBTRIGGTIMER:
15853 {
15854 if(auto* trig = get_combo_trigger(ri->combotrigref))
15855 {
15856 trig->trig_statetime = vbound(value/10000, 0, 214748);
15857 }
15858 break;
15859 }
15860 case CMBTRIGGENSCRIPT:
15861 {
15862 if(auto* trig = get_combo_trigger(ri->combotrigref))
15863 {
15864 trig->trig_genscr = vbound(value/10000, 0, 65535);
15865 }
15866 break;
15867 }
15868 case CMBTRIGGROUP:
15869 {
15870 if(auto* trig = get_combo_trigger(ri->combotrigref))
15871 {
15872 trig->trig_group = vbound(value/10000, 0, 255);
15873 }
15874 break;
15875 }
15876 case CMBTRIGGROUPVAL:
15877 {
15878 if(auto* trig = get_combo_trigger(ri->combotrigref))
15879 {
15880 trig->trig_group_val = vbound(value/10000, 0, 65535);
15881 }
15882 break;
15883 }
15884 case CMBTRIGLITEMS:
15885 {
15886 if(auto* trig = get_combo_trigger(ri->combotrigref))
15887 {
15888 trig->trig_levelitems = (value/10000) & liALL;
15889 }
15890 break;
15891 }
15892 case CMBTRIGDMAPLVL:
15893 {
15894 if(auto* trig = get_combo_trigger(ri->combotrigref))
15895 {
15896 trig->trigdmlevel = vbound(value/10000, -1, MAXLEVELS-1);
15897 }
15898 break;
15899 }
15900 case CMBTRIGTINTR:
15901 {
15902 if(auto* trig = get_combo_trigger(ri->combotrigref))
15903 {
15904 trig->trigtint[0] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15905 }
15906 break;
15907 }
15908 case CMBTRIGTINTG:
15909 {
15910 if(auto* trig = get_combo_trigger(ri->combotrigref))
15911 {
15912 trig->trigtint[1] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15913 }
15914 break;
15915 }
15916 case CMBTRIGTINTB:
15917 {
15918 if(auto* trig = get_combo_trigger(ri->combotrigref))
15919 {
15920 trig->trigtint[2] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15921 }
15922 break;
15923 }
15924 case CMBTRIGLVLPAL:
15925 {
15926 if(auto* trig = get_combo_trigger(ri->combotrigref))
15927 {
15928 trig->triglvlpalette = vbound(value/10000, -1, 512);
15929 }
15930 break;
15931 }
15932 case CMBTRIGBOSSPAL:
15933 {
15934 if(auto* trig = get_combo_trigger(ri->combotrigref))
15935 {
15936 trig->trigbosspalette = vbound(value/10000, -1, 29);
15937 }
15938 break;
15939 }
15940 case CMBTRIGQUAKETIME:
15941 {
15942 if(auto* trig = get_combo_trigger(ri->combotrigref))
15943 {
15944 trig->trigquaketime = zc_max(value/10000, -1);
15945 }
15946 break;
15947 }
15948 case CMBTRIGWAVYTIME:
15949 {
15950 if(auto* trig = get_combo_trigger(ri->combotrigref))
15951 {
15952 trig->trigwavytime = zc_max(value/10000, -1);
15953 }
15954 break;
15955 }
15956 case CMBTRIGSWORDJINX:
15957 {
15958 if(auto* trig = get_combo_trigger(ri->combotrigref))
15959 {
15960 trig->trig_swjinxtime = zc_max(value/10000, -2);
15961 }
15962 break;
15963 }
15964 case CMBTRIGITEMJINX:
15965 {
15966 if(auto* trig = get_combo_trigger(ri->combotrigref))
15967 {
15968 trig->trig_itmjinxtime = zc_max(value/10000, -2);
15969 }
15970 break;
15971 }
15972 case CMBTRIGSHIELDJINX:
15973 {
15974 if(auto* trig = get_combo_trigger(ri->combotrigref))
15975 {
15976 trig->trig_shieldjinxtime = zc_max(value/10000, -2);
15977 }
15978 break;
15979 }
15980 case CMBTRIGSTUN:
15981 {
15982 if(auto* trig = get_combo_trigger(ri->combotrigref))
15983 {
15984 trig->trig_stuntime = zc_max(value/10000, -2);
15985 }
15986 break;
15987 }
15988 case CMBTRIGBUNNY:
15989 {
15990 if(auto* trig = get_combo_trigger(ri->combotrigref))
15991 {
15992 trig->trig_bunnytime = zc_max(value/10000, -2);
15993 }
15994 break;
15995 }
15996 case CMBTRIGPUSHTIME:
15997 {
15998 if(auto* trig = get_combo_trigger(ri->combotrigref))
15999 {
16000 trig->trig_pushtime = vbound(value/10000, 0, 255);
16001 }
16002 break;
16003 }
16004 case CMBTRIGGERPROMPTCID:
16005 {
16006 if(auto* trig = get_combo_trigger(ri->combotrigref))
16007 trig->prompt_cid = vbound(value/10000, 0, MAXCOMBOS-1);
16008 break;
16009 }
16010 case CMBTRIGGERPROMPTCS:
16011 {
16012 if(auto* trig = get_combo_trigger(ri->combotrigref))
16013 trig->prompt_cs = (value/10000)&15;
16014 break;
16015 }
16016 case CMBTRIGGERFAILPROMPTCID:
16017 {
16018 if(auto* trig = get_combo_trigger(ri->combotrigref))
16019 trig->fail_prompt_cid = vbound(value/10000, 0, MAXCOMBOS-1);
16020 break;
16021 }
16022 case CMBTRIGGERFAILPROMPTCS:
16023 {
16024 if(auto* trig = get_combo_trigger(ri->combotrigref))
16025 trig->fail_prompt_cs = (value/10000)&15;
16026 break;
16027 }
16028 case CMBTRIGGERPROMPTX:
16029 {
16030 if(auto* trig = get_combo_trigger(ri->combotrigref))
16031 trig->prompt_x = vbound(value/10000, -32768, 32767);
16032 break;
16033 }
16034 case CMBTRIGGERPROMPTY:
16035 {
16036 if(auto* trig = get_combo_trigger(ri->combotrigref))
16037 trig->prompt_y = vbound(value/10000, -32768, 32767);
16038 break;
16039 }
16040 case CMBTRIGGERTRIGSTR:
16041 {
16042 if(auto* trig = get_combo_trigger(ri->combotrigref))
16043 trig->trig_msgstr = vbound(value/10000, 0, msg_count-1);
16044 break;
16045 }
16046 case CMBTRIGGERFAILSTR:
16047 {
16048 if(auto* trig = get_combo_trigger(ri->combotrigref))
16049 trig->fail_msgstr = vbound(value/10000, 0, msg_count-1);
16050 break;
16051 }
16052 case CMBTRIGGERPLAYERBOUNCE:
16053 {
16054 if(auto* trig = get_combo_trigger(ri->combotrigref))
16055 trig->player_bounce = zslongToFix(value);
16056 break;
16057 }
16058 case CMBTRIGGERREQPLAYERZ:
16059 {
16060 if(auto* trig = get_combo_trigger(ri->combotrigref))
16061 trig->req_player_z = zslongToFix(value);
16062 break;
16063 }
16064 case CMBTRIGGERDESTHEROX:
16065 {
16066 if(auto* trig = get_combo_trigger(ri->combotrigref))
16067 trig->dest_player_x = zslongToFix(value);
16068 break;
16069 }
16070 case CMBTRIGGERDESTHEROY:
16071 {
16072 if(auto* trig = get_combo_trigger(ri->combotrigref))
16073 trig->dest_player_y = zslongToFix(value);
16074 break;
16075 }
16076 case CMBTRIGGERDESTHEROZ:
16077 {
16078 if(auto* trig = get_combo_trigger(ri->combotrigref))
16079 trig->dest_player_z = zslongToFix(value);
16080 break;
16081 }
16082 case CMBTRIGGERREQPLAYERJUMP:
16083 {
16084 if(auto* trig = get_combo_trigger(ri->combotrigref))
16085 trig->req_player_jump = zslongToFix(value);
16086 break;
16087 }
16088 case CMBTRIGGERREQPLAYERX:
16089 {
16090 if(auto* trig = get_combo_trigger(ri->combotrigref))
16091 trig->req_player_x = zslongToFix(value);
16092 break;
16093 }
16094 case CMBTRIGGERREQPLAYERY:
16095 {
16096 if(auto* trig = get_combo_trigger(ri->combotrigref))
16097 trig->req_player_y = zslongToFix(value);
16098 break;
16099 }
16100 case CMBTRIGGERFORCEPLAYERDIR:
16101 {
16102 if(auto* trig = get_combo_trigger(ri->combotrigref))
16103 trig->dest_player_dir = vbound(value/10000, 3, -1);
16104 break;
16105 }
16106 case CMBTRIGGERICECOMBO:
16107 {
16108 if(auto* trig = get_combo_trigger(ri->combotrigref))
16109 trig->force_ice_combo = vbound(value/10000, MAXCOMBOS-1, -1);
16110 break;
16111 }
16112 case CMBTRIGGERICEVX:
16113 {
16114 if(auto* trig = get_combo_trigger(ri->combotrigref))
16115 trig->force_ice_vx = zslongToFix(value);
16116 break;
16117 }
16118 case CMBTRIGGERICEVY:
16119 {
16120 if(auto* trig = get_combo_trigger(ri->combotrigref))
16121 trig->force_ice_vy = zslongToFix(value);
16122 break;
16123 }
16124 ///----------------------------------------------------------------------------------------------------//
16125 //npcdata nd-> Variables
16126
16127 #define SET_NPCDATA_VAR_INT(member, str) \
16128 { \
16129 if( auto nd = checkNPCData(ri->npcdataref) ) \
16130 nd->member = vbound((value / 10000),0,214747); \
16131 } \
16132
16133 #define SET_NPCDATA_VAR_DWORD(member, str) \
16134 { \
16135 if( auto nd = checkNPCData(ri->npcdataref) ) \
16136 nd->member = vbound((value / 10000),0,32767); \
16137 } \
16138
16139 #define SET_NPCDATA_VAR_ENUM(member, str) \
16140 { \
16141 if( auto nd = checkNPCData(ri->npcdataref) ) \
16142 nd->member = (decltype(guysbuf[ri->npcdataref].member))vbound((value / 10000),0,32767); \
16143 } \
16144
16145 #define SET_NPCDATA_VAR_BYTE(member, str) \
16146 { \
16147 if( auto nd = checkNPCData(ri->npcdataref) ) \
16148 nd->member = vbound((value / 10000),0,255); \
16149 } \
16150
16151 #define SET_NPCDATA_FLAG(member, str) \
16152 { \
16153 int32_t flag = (value/10000); \
16154 if( auto nd = checkNPCData(ri->npcdataref) ) \
16155 { \
16156 if ( flag ) \
16157 { \
16158 nd->member|=flag; \
16159 } \
16160 else nd->member|= ~flag; \
16161 } \
16162 } \
16163
16164 case NPCDATATILE: SET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
16165 case NPCDATAWIDTH: SET_NPCDATA_VAR_BYTE(width, "Width"); break;
16166 case NPCDATAHEIGHT: SET_NPCDATA_VAR_BYTE(height, "Height"); break;
16167 case NPCDATAFLAGS1: SET_NPCDATA_VAR_ENUM(flags, "Flags (deprecated)"); break;
16168 case NPCDATAFLAGS2: SET_NPCDATA_VAR_ENUM(flags, "Flags2 (deprecated)"); break;
16169 case NPCDATASTILE: SET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
16170 case NPCDATASWIDTH: SET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
16171 case NPCDATASHEIGHT: SET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
16172 case NPCDATAETILE: SET_NPCDATA_VAR_INT(e_tile, "ExTile"); break;
16173 case NPCDATAEWIDTH: SET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
16174 case NPCDATASCRIPT: SET_NPCDATA_VAR_BYTE(script, "Script"); break;
16175 case NPCDATAEHEIGHT: SET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
16176 case NPCDATAHP: SET_NPCDATA_VAR_DWORD(hp, "HP"); break;
16177 case NPCDATAFAMILY: SET_NPCDATA_VAR_DWORD(family, "Family"); break;
16178 case NPCDATACSET: SET_NPCDATA_VAR_DWORD(cset, "CSet"); break;
16179 case NPCDATAANIM: SET_NPCDATA_VAR_DWORD(anim, "Anim"); break;
16180 case NPCDATAEANIM: SET_NPCDATA_VAR_DWORD(e_anim, "ExAnim"); break;
16181 case NPCDATAFRAMERATE: SET_NPCDATA_VAR_DWORD(frate, "Framerate"); break;
16182 case NPCDATAEFRAMERATE: SET_NPCDATA_VAR_DWORD(e_frate, "ExFramerate"); break;
16183 case NPCDATATOUCHDAMAGE: SET_NPCDATA_VAR_DWORD(dp, "TouchDamage"); break;
16184 case NPCDATAWEAPONDAMAGE: SET_NPCDATA_VAR_DWORD(wdp, "WeaponDamage"); break;
16185 case NPCDATAWEAPON: SET_NPCDATA_VAR_DWORD(weapon, "Weapon"); break;
16186 case NPCDATARANDOM: SET_NPCDATA_VAR_DWORD(rate, "Random"); break;
16187 case NPCDATAHALT: SET_NPCDATA_VAR_DWORD(hrate, "Haltrate"); break;
16188 case NPCDATASTEP: SET_NPCDATA_VAR_DWORD(step, "Step"); break;
16189 case NPCDATAHOMING: SET_NPCDATA_VAR_DWORD(homing, "Homing"); break;
16190 case NPCDATAHUNGER: SET_NPCDATA_VAR_DWORD(grumble, "Hunger"); break;
16191 case NPCDATADROPSET: SET_NPCDATA_VAR_DWORD(item_set, "Dropset"); break;
16192 case NPCDATABGSFX: SET_NPCDATA_VAR_DWORD(bgsfx, "BGSFX"); break;
16193 case NPCDATADEATHSFX: SET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
16194 case NPCDATAHITSFX: SET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
16195 case NPCDATAXOFS: SET_NPCDATA_VAR_INT(xofs, "DrawXOffset"); break;
16196 case NPCDATAYOFS: SET_NPCDATA_VAR_INT(yofs, "DrawYOffset"); break;
16197 case NPCDATAZOFS: SET_NPCDATA_VAR_INT(zofs, "DrawZOffset"); break;
16198 case NPCDATAHXOFS: SET_NPCDATA_VAR_INT(hxofs, "HitXOffset"); break;
16199 case NPCDATAHYOFS: SET_NPCDATA_VAR_INT(hyofs, "HitYOffset"); break;
16200 case NPCDATAHITWIDTH: SET_NPCDATA_VAR_INT(hxsz, "HitWidth"); break;
16201 case NPCDATAHITHEIGHT: SET_NPCDATA_VAR_INT(hysz, "HitHeight"); break;
16202 case NPCDATAHITZ: SET_NPCDATA_VAR_INT(hzsz, "HitZHeight"); break;
16203 case NPCDATATILEWIDTH: SET_NPCDATA_VAR_INT(txsz, "TileWidth"); break;
16204 case NPCDATATILEHEIGHT: SET_NPCDATA_VAR_INT(tysz, "TileHeight"); break;
16205 case NPCDATAWPNSPRITE: SET_NPCDATA_VAR_INT(wpnsprite, "WeaponSprite"); break;
16206 case NPCDATAWEAPONSCRIPT:
16207 {
16208 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
16209 Z_scripterrlog("Invalid NPC ID passed to npcdata->WeaponScript: %d\n", (ri->npcdataref*10000));
16210 else
16211 guysbuf[ri->npcdataref].weap_data.script = vbound((value / 10000),0,214747);
16212 break;
16213 }
16214 case NPCDATASIZEFLAG: SET_NPCDATA_VAR_INT(SIZEflags, "SizeFlags"); break;
16215
16216 case NPCDATAFROZENTILE: SET_NPCDATA_VAR_INT(frozentile, "FrozenTile"); break;
16217 case NPCDATAFROZENCSET: SET_NPCDATA_VAR_INT(frozencset, "FrozenCSet"); break;
16218 case NPCDATAFIRESFX: SET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
16219
16220 case NPCDSHADOWSPR:
16221 {
16222 if(ri->npcdataref > (MAXNPCS-1) )
16223 {
16224 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
16225 }
16226 else
16227 {
16228 guysbuf[ri->npcdataref].spr_shadow = vbound(value/10000, 0, 255);
16229 }
16230 break;
16231 }
16232 case NPCDSPAWNSPR:
16233 {
16234 if(ri->npcdataref > (MAXNPCS-1) )
16235 {
16236 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
16237 }
16238 else
16239 {
16240 guysbuf[ri->npcdataref].spr_spawn = vbound(value/10000, 0, 255);
16241 }
16242 break;
16243 }
16244 case NPCDDEATHSPR:
16245 {
16246 if(ri->npcdataref > (MAXNPCS-1) )
16247 {
16248 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
16249 }
16250 else
16251 {
16252 guysbuf[ri->npcdataref].spr_death = vbound(value/10000, 0, 255);
16253 }
16254 break;
16255 }
16256
16257
16258 ///----------------------------------------------------------------------------------------------------//
16259 //Dropset Variables
16260
16261 case DROPSETNULLCHANCE:
16262 {
16263 if(ri->dropsetref > MAXITEMDROPSETS)
16264 {
16265 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
16266 break;
16267 }
16268 item_drop_sets[ri->dropsetref].chance[0] = vbound((value / 10000),0,32767);
16269 break;
16270 }
16271
16272 ///----------------------------------------------------------------------------------------------------//
16273 //Audio Variables
16274
16275 case AUDIOPAN:
16276 {
16277 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE) )
16278 {
16279 FFCore.usr_panstyle = FFScript::do_getSFX_pan();
16280 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_PANSTYLE,true);
16281 }
16282 FFScript::do_setSFX_pan(value/10000);
16283 break;
16284 }
16285
16286 ///----------------------------------------------------------------------------------------------------//
16287 //Graphics->
16288
16289 case NUMDRAWS:
16290 break;
16291
16292 case MAXDRAWS: break;
16293
16294 ///----------------------------------------------------------------------------------------------------//
16295 //Misc./Internal
16296 case SP:
16297 ri->sp = value / 10000;
16298 break;
16299
16300 case SP2:
16301 ri->sp = value;
16302 break;
16303
16304 case PC:
16305 ri->pc = value;
16306 break;
16307
16308 case SWITCHKEY:
16309 444726 ri->switchkey = value;
16310 444726 break;
16311
16312 case SCRIPTRAM:
16313 case GLOBALRAM:
16314 531793831 ArrayH::setElement(ri->d[rINDEX], ri->d[rINDEX2] / 10000, value);
16315 531793831 break;
16316
16317 case SCRIPTRAMD:
16318 case GLOBALRAMD:
16319 ArrayH::setElement(ri->d[rINDEX], 0, value);
16320 break;
16321
16322 case REFFFC:
16323
2/2
✓ Branch 0 taken 6374738 times.
✓ Branch 1 taken 639949427 times.
646324165 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? value : value / 10000;
16324 646324165 break;
16325
16326 case REFITEM:
16327 2239361 ri->itemref = value;
16328 2239361 break;
16329
16330 case REFITEMCLASS:
16331 6367264 ri->idata = value;
16332 6367264 break;
16333
16334 case REFLWPN:
16335 12117383 ri->lwpn = value;
16336 12117383 break;
16337
16338 case REFEWPN:
16339 46788128 ri->ewpn = value;
16340 46788128 break;
16341
16342 case REFNPC:
16343 162664402 ri->guyref = value;
16344 162664402 break;
16345
16346 case REFSPRITE:
16347 43220119 ri->spriteref = value;
16348 43220119 break;
16349
16350 88305847 case REFMAPDATA: ri->mapsref = value; break;
16351 case REFSCREENDATA: ri->screenref = value; break;
16352 838813 case REFCOMBODATA: ri->combosref = value; break;
16353 case REFCOMBOTRIGGER: ri->combotrigref = value; break;
16354 64 case REFSPRITEDATA: ri->spritedataref = value; break;
16355 410111 case REFBITMAP: ri->bitmapref = value; break;
16356 1 case REFNPCCLASS: ri->npcdataref = value; break;
16357
16358 77218 case REFDMAPDATA: ri->dmapsref = value; break;
16359 case REFSHOPDATA: ri->shopsref = value; break;
16360 124 case REFMSGDATA: ri->zmsgref = value; break;
16361
16362
16363 10 case REFDROPS: ri->dropsetref = value; break;
16364 case REFBOTTLETYPE: ri->bottletyperef = value; break;
16365 case REFBOTTLESHOP: ri->bottleshopref = value; break;
16366 8474727 case REFGENERICDATA: ri->genericdataref = value; break;
16367 284 case REFFILE: ri->fileref = value; break;
16368 case REFDIRECTORY: ri->directoryref = value; break;
16369 case REFSTACK: ri->stackref = value; break;
16370 109743 case REFSUBSCREEN: ri->subdataref = value; break;
16371 20806 case REFSUBSCREENPAGE: ri->subpageref = value; break;
16372 103742 case REFSUBSCREENWIDG: ri->subwidgref = value; break;
16373 449481 case REFRNG: ri->rngref = value; break;
16374 case REFWEBSOCKET: ri->websocketref = value; break;
16375 3393 case CLASS_THISKEY: ri->thiskey = value; break;
16376 1119 case CLASS_THISKEY2: ri->thiskey2 = value; break;
16377 7263 case REFPALDATA: ri->paldataref = value; break;
16378
16379 //-------------------------------------------------------------------------------------------------
16380
16381 case GENDATARUNNING:
16382 {
16383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 121 times.
121 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
16384 {
16385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 121 times.
121 if(value)
16386 121 scr->launch();
16387 else scr->quit();
16388 121 }
16389 121 break;
16390 }
16391 case GENDATASIZE:
16392 {
16393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
16394 {
16395 38 scr->dataResize(value/10000);
16396 38 }
16397 38 break;
16398 }
16399
16400 //----------------------------------------------------------------------------------------------------//
16401
16402 case PORTALX:
16403 {
16404 if(portal* p = checkPortal(ri->portalref))
16405 p->x = zslongToFix(value);
16406 break;
16407 }
16408 case PORTALY:
16409 {
16410 if(portal* p = checkPortal(ri->portalref))
16411 p->y = zslongToFix(value);
16412 break;
16413 }
16414 case PORTALDMAP:
16415 {
16416 if(portal* p = checkPortal(ri->portalref))
16417 p->destdmap = vbound(value/10000,-1,MAXDMAPS-1);
16418 break;
16419 }
16420 case PORTALSCREEN:
16421 {
16422 if(portal* p = checkPortal(ri->portalref))
16423 p->destscr = vbound(value/10000,0,255);
16424 break;
16425 }
16426 case PORTALACLK:
16427 {
16428 if(portal* p = checkPortal(ri->portalref))
16429 p->aclk = vbound(value/10000, 0, 9999);
16430 break;
16431 }
16432 case PORTALAFRM:
16433 {
16434 if(portal* p = checkPortal(ri->portalref))
16435 p->aframe = vbound(value/10000, 0, 9999);
16436 break;
16437 }
16438 case PORTALOTILE:
16439 {
16440 if(portal* p = checkPortal(ri->portalref))
16441 p->o_tile = vbound(value/10000, 0, NEWMAXTILES-1);
16442 break;
16443 }
16444 case PORTALASPD:
16445 {
16446 if(portal* p = checkPortal(ri->portalref))
16447 p->aspd = vbound(value/10000, 0, 9999);
16448 break;
16449 }
16450 case PORTALFRAMES:
16451 {
16452 if(portal* p = checkPortal(ri->portalref))
16453 p->frames = vbound(value/10000, 0, 9999);
16454 break;
16455 }
16456 case PORTALSAVED:
16457 {
16458 if(ri->portalref < 0 || value < 0) break;
16459 if(portal* p = checkPortal(ri->portalref))
16460 {
16461 if(!value)
16462 p->saved_data = 0;
16463 else if(savedportal* sp = checkSavedPortal(value))
16464 p->saved_data = sp->getUID();
16465 }
16466 break;
16467 }
16468 case PORTALCLOSEDIS:
16469 {
16470 if(portal* p = checkPortal(ri->portalref))
16471 p->prox_active = value==0; //Inverted
16472 break;
16473 }
16474 case REFPORTAL:
16475 {
16476 ri->portalref = value;
16477 break;
16478 }
16479 case REFSAVPORTAL:
16480 {
16481 ri->saveportalref = value;
16482 break;
16483 }
16484 case PORTALWARPSFX:
16485 {
16486 if(portal* p = checkPortal(ri->portalref))
16487 p->wsfx = vbound(value/10000,0,255);
16488 break;
16489 }
16490 case PORTALWARPVFX:
16491 {
16492 if(portal* p = checkPortal(ri->portalref))
16493 p->weffect = vbound(value/10000,0,255);
16494 break;
16495 }
16496 case SAVEDPORTALX:
16497 {
16498 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16499 p->x = value;
16500 break;
16501 }
16502 case SAVEDPORTALY:
16503 {
16504 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16505 p->y = value;
16506 break;
16507 }
16508 case SAVEDPORTALSRCDMAP:
16509 {
16510 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16511 p->srcdmap = vbound(value/10000, -1, MAXDMAPS-1);
16512 break;
16513 }
16514 case SAVEDPORTALDESTDMAP:
16515 {
16516 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16517 p->destdmap = vbound(value/10000, -1, MAXDMAPS-1);
16518 break;
16519 }
16520 case SAVEDPORTALSRCSCREEN:
16521 {
16522 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16523 p->srcscr = vbound(value/10000,0,255);
16524 break;
16525 }
16526 case SAVEDPORTALDSTSCREEN:
16527 {
16528 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16529 p->destscr = vbound(value/10000,0,255);
16530 break;
16531 }
16532 case SAVEDPORTALWARPSFX:
16533 {
16534 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16535 p->sfx = vbound(value/10000,0,255);
16536 break;
16537 }
16538 case SAVEDPORTALWARPVFX:
16539 {
16540 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16541 p->warpfx = vbound(value/10000,0,255);
16542 break;
16543 }
16544 case SAVEDPORTALSPRITE:
16545 {
16546 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16547 p->spr = vbound(value/10000,0,255);
16548 break;
16549 }
16550 case SAVEDPORTALPORTAL:
16551 {
16552 if(ri->saveportalref < 0 || value < 0) break;
16553 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
16554 {
16555 int32_t id = getPortalFromSaved(sp);
16556 if(id == value) break; //no change
16557 portal* p = checkPortal(value);
16558 if(p)
16559 {
16560 p->saved_data = sp->getUID();
16561 if(id > 0)
16562 {
16563 portal* p = checkPortal(id);
16564 p->saved_data = 0;
16565 }
16566 }
16567 }
16568 break;
16569 }
16570
16571 case GAMENUMASUB:
16572 {
16573 if(value >= 0)
16574 {
16575 size_t sz = vbound(value/10000, 0, 256);
16576 while(subscreens_active.size() < sz)
16577 {
16578 auto& sub = subscreens_active.emplace_back();
16579 sub.sub_type = sstACTIVE;
16580 }
16581 while(subscreens_active.size() > sz)
16582 subscreens_active.pop_back();
16583 }
16584 break;
16585 }
16586 case GAMENUMPSUB:
16587 {
16588 if(value >= 0)
16589 {
16590 size_t sz = vbound(value/10000, 0, 256);
16591 while(subscreens_passive.size() < sz)
16592 {
16593 auto& sub = subscreens_passive.emplace_back();
16594 sub.sub_type = sstPASSIVE;
16595 }
16596 while(subscreens_passive.size() > sz)
16597 subscreens_passive.pop_back();
16598 }
16599 break;
16600 }
16601 case GAMENUMOSUB:
16602 {
16603 if(value >= 0)
16604 {
16605 size_t sz = vbound(value/10000, 0, 256);
16606 while(subscreens_overlay.size() < sz)
16607 {
16608 auto& sub = subscreens_overlay.emplace_back();
16609 sub.sub_type = sstOVERLAY;
16610 }
16611 while(subscreens_overlay.size() > sz)
16612 subscreens_overlay.pop_back();
16613 }
16614 break;
16615 }
16616 ///----------------------------------------------------------------------------------------------------//
16617
16618 case SUBDATACURPG:
16619 {
16620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
16621
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
6 if(sub->sub_type == sstACTIVE)
16622 3 sub->curpage = vbound(value/10000,0,sub->pages.size()-1);
16623 3 break;
16624 }
16625 case SUBDATANUMPG:
16626 {
16627 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
16628 if(sub->sub_type == sstACTIVE && value >= 10000)
16629 {
16630 size_t sz = value/10000;
16631 while(sub->pages.size() < sz)
16632 if(!sub->add_page(MAX_SUBSCR_PAGES))
16633 break;
16634 while(sub->pages.size() > sz)
16635 sub->delete_page(sub->pages.size()-1);
16636 }
16637 break;
16638 }
16639 case SUBDATATYPE: break; //READONLY
16640 ///---- ACTIVE SUBSCREENS ONLY
16641 case SUBDATACURSORPOS:
16642 {
16643 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16644 {
16645 SubscrPage& pg = sub->cur_page();
16646 //Should this be sanity checked? Or should nulling out
16647 // the cursor by setting it invalid be allowed? -Em
16648 pg.cursor_pos = vbound(value/10000,0,255);
16649 }
16650 break;
16651 }
16652 case SUBDATASCRIPT:
16653 {
16654 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16655 sub->script = vbound(value/10000,0,NUMSCRIPTSSUBSCREEN-1);
16656 break;
16657 }
16658
16659 case SUBDATATRANSLEFTTY:
16660 {
16661 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16662 {
16663 auto& trans = sub->trans_left;
16664 trans.type = vbound(value/10000,0,sstrMAX-1);
16665 }
16666 break;
16667 }
16668 case SUBDATATRANSLEFTSFX:
16669 {
16670 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16671 {
16672 auto& trans = sub->trans_left;
16673 trans.tr_sfx = vbound(value/10000,0,255);
16674 }
16675 break;
16676 }
16677 case SUBDATATRANSRIGHTTY:
16678 {
16679 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16680 {
16681 auto& trans = sub->trans_right;
16682 trans.type = vbound(value/10000,0,sstrMAX-1);
16683 }
16684 break;
16685 }
16686 case SUBDATATRANSRIGHTSFX:
16687 {
16688 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16689 {
16690 auto& trans = sub->trans_right;
16691 trans.tr_sfx = vbound(value/10000,0,255);
16692 }
16693 break;
16694 }
16695 case SUBDATASELECTORDSTX:
16696 {
16697 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16698 sub->selector_setting.x = vbound(value/10000,-32768,32767);
16699 break;
16700 }
16701 case SUBDATASELECTORDSTY:
16702 {
16703 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16704 sub->selector_setting.y = vbound(value/10000,-32768,32767);
16705 break;
16706 }
16707 case SUBDATASELECTORDSTW:
16708 {
16709 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16710 sub->selector_setting.w = vbound(value/10000,-32768,32767);
16711 break;
16712 }
16713 case SUBDATASELECTORDSTH:
16714 {
16715 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16716 sub->selector_setting.h = vbound(value/10000,-32768,32767);
16717 break;
16718 }
16719 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
16720 case SUBDATATRANSCLK:
16721 {
16722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16723 {
16724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
16725 Z_scripterrlog("'subscreendata->TransClock' is only"
16726 " valid for the current active subscreen!\n");
16727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16728 {
16729 11 int val = value/10000;
16730
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(val < 0)
16731 subscrpg_clear_animation();
16732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(!subscr_pg_animating)
16733 {
16734 11 SubscrTransition tr = subscr_pg_transition;
16735 11 tr.tr_sfx = 0;
16736 11 subscrpg_animate(subscr_pg_from,subscr_pg_to,tr,*new_subscreen_active);
16737 11 subscr_pg_clk = val;
16738 11 }
16739 else subscr_pg_clk = val;
16740 11 }
16741 11 }
16742 11 break;
16743 }
16744 case SUBDATATRANSTY:
16745 {
16746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16747 {
16748 11 auto& trans = subscr_pg_transition;
16749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
16750 Z_scripterrlog("'subscreendata->TransType' is only"
16751 " valid for the current active subscreen!\n");
16752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16753 11 trans.type = vbound(value/10000,0,sstrMAX-1);
16754 11 }
16755 11 break;
16756 }
16757 case SUBDATATRANSFROMPG:
16758 {
16759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16760 {
16761
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(sub != new_subscreen_active)
16762 Z_scripterrlog("'subscreendata->TransFromPage' is only"
16763 " valid for the current active subscreen!\n");
16764
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16765 11 subscr_pg_from = vbound(value/10000,0,sub->pages.size()-1);
16766 11 }
16767 11 break;
16768 }
16769 case SUBDATATRANSTOPG:
16770 {
16771
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16772 {
16773
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(sub != new_subscreen_active)
16774 Z_scripterrlog("'subscreendata->TransToPage' is only"
16775 " valid for the current active subscreen!\n");
16776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16777 11 subscr_pg_to = vbound(value/10000,0,sub->pages.size()-1);
16778 11 }
16779 11 break;
16780 }
16781
16782 ///----------------------------------------------------------------------------------------------------//
16783 case SUBPGINDEX: break; //READ-ONLY
16784 case SUBPGNUMWIDG: break; //READ-ONLY
16785 case SUBPGSUBDATA: break; //READ-ONLY
16786 case SUBPGCURSORPOS:
16787 {
16788 if(SubscrPage* pg = checkSubPage(ri->subpageref))
16789 pg->cursor_pos = vbound(value/10000,0,255);
16790 break;
16791 }
16792 ///----------------------------------------------------------------------------------------------------//
16793 ///---- ANY WIDGET TYPE
16794 case SUBWIDGTYPE: break; //READ-ONLY
16795 case SUBWIDGINDEX: break; //READ-ONLY
16796 case SUBWIDGPAGE: break; //READ-ONLY
16797 case SUBWIDGDISPITM: break; //READ-ONLY
16798 case SUBWIDGEQPITM: break; //READ-ONLY
16799 case SUBWIDGPOS:
16800 {
16801 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16802 widg->pos = vbound(value/10000,0,255);
16803 break;
16804 }
16805 case SUBWIDGX:
16806 {
16807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16808 132 widg->x = vbound(value/10000,-32768,32767);
16809 132 break;
16810 }
16811 case SUBWIDGY:
16812 {
16813
1/2
✓ Branch 0 taken 4247 times.
✗ Branch 1 not taken.
4247 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16814 4247 widg->y = vbound(value/10000,-32768,32767);
16815 4247 break;
16816 }
16817 case SUBWIDGW:
16818 {
16819 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16820 widg->w = vbound(value/10000,0,65535);
16821 break;
16822 }
16823 case SUBWIDGH:
16824 {
16825 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16826 widg->h = vbound(value/10000,0,65535);
16827 break;
16828 }
16829 case SUBWIDGREQCOUNTER:
16830 {
16831 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16832 widg->req_counter = vbound(value/10000,sscMIN,MAX_COUNTERS);
16833 break;
16834 }
16835 case SUBWIDGREQCOUNTERCOND:
16836 {
16837 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16838 widg->req_counter_cond_type = vbound(value/10000,CONDTY_NONE,CONDTY_MAX-1);
16839 break;
16840 }
16841 case SUBWIDGREQCOUNTERVAL:
16842 {
16843 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16844 widg->req_counter_val = vbound(value/10000,0,65535);
16845 break;
16846 }
16847 case SUBWIDGREQLITEMS:
16848 {
16849 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16850 widg->req_litems = vbound(value/10000,0,liALL);
16851 break;
16852 }
16853 case SUBWIDGREQLITEMLEVEL:
16854 {
16855 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16856 widg->req_litem_level = vbound(value/10000,-1,MAXLEVELS);
16857 break;
16858 }
16859 case SUBWIDGREQSCRIPTDISABLED:
16860 {
16861 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16862 widg->is_disabled = value != 0;
16863 break;
16864 }
16865 ///---- ACTIVE SUBSCREENS ONLY
16866 case SUBWIDGSELECTORDSTX:
16867 {
16868 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16869 widg->selector_override.x = vbound(value/10000,-32768,32767);
16870 break;
16871 }
16872 case SUBWIDGSELECTORDSTY:
16873 {
16874 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16875 widg->selector_override.y = vbound(value/10000,-32768,32767);
16876 break;
16877 }
16878 case SUBWIDGSELECTORDSTW:
16879 {
16880 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16881 widg->selector_override.w = vbound(value/10000,-32768,32767);
16882 break;
16883 }
16884 case SUBWIDGSELECTORDSTH:
16885 {
16886 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16887 widg->selector_override.h = vbound(value/10000,-32768,32767);
16888 break;
16889 }
16890
16891 case SUBWIDGPRESSSCRIPT:
16892 {
16893 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16894 widg->generic_script = vbound(value/10000,0,NUMSCRIPTSGENERIC-1);
16895 break;
16896 }
16897 case SUBWIDGPGMODE:
16898 {
16899 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16900 widg->pg_mode = vbound(value/10000,0,PGGOTO_MAX-1);
16901 break;
16902 }
16903 case SUBWIDGPGTARG:
16904 {
16905 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16906 widg->pg_targ = vbound(value/10000,0,MAX_SUBSCR_PAGES-1);
16907 break;
16908 }
16909
16910 case SUBWIDGTRANSPGTY:
16911 {
16912 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16913 {
16914 auto& trans = widg->pg_trans;
16915 trans.type = vbound(value/10000,0,sstrMAX-1);
16916 }
16917 break;
16918 }
16919 case SUBWIDGTRANSPGSFX:
16920 {
16921 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16922 {
16923 auto& trans = widg->pg_trans;
16924 trans.tr_sfx = vbound(value/10000,0,255);
16925 }
16926 break;
16927 }
16928 case SUBWIDGTY_FONT:
16929 {
16930 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16931 {
16932 auto val = vbound(value/10000,0,font_max-1);
16933 auto ty = widg->getType();
16934 switch(ty)
16935 {
16936 case widgTEXT:
16937 ((SW_Text*)widg)->fontid = val;
16938 break;
16939 case widgTEXTBOX:
16940 ((SW_TextBox*)widg)->fontid = val;
16941 break;
16942 case widgSELECTEDTEXT:
16943 ((SW_SelectedText*)widg)->fontid = val;
16944 break;
16945 case widgTIME:
16946 ((SW_Time*)widg)->fontid = val;
16947 break;
16948 case widgCOUNTER:
16949 ((SW_Counter*)widg)->fontid = val;
16950 break;
16951 case widgBTNCOUNTER:
16952 ((SW_BtnCounter*)widg)->fontid = val;
16953 break;
16954 case widgOLDCTR:
16955 ((SW_Counters*)widg)->fontid = val;
16956 break;
16957 case widgMMAPTITLE:
16958 ((SW_MMapTitle*)widg)->fontid = val;
16959 break;
16960 default:
16961 bad_subwidg_type(false, ty);
16962 break;
16963 }
16964 }
16965 break;
16966 }
16967 case SUBWIDGTY_ALIGN:
16968 {
16969 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16970 {
16971 auto val = vbound(value/10000,0,sstaMAX-1);
16972 auto ty = widg->getType();
16973 switch(ty)
16974 {
16975 case widgTEXT:
16976 ((SW_Text*)widg)->align = val;
16977 break;
16978 case widgTEXTBOX:
16979 ((SW_TextBox*)widg)->align = val;
16980 break;
16981 case widgSELECTEDTEXT:
16982 ((SW_SelectedText*)widg)->align = val;
16983 break;
16984 case widgTIME:
16985 ((SW_Time*)widg)->align = val;
16986 break;
16987 case widgCOUNTER:
16988 ((SW_Counter*)widg)->align = val;
16989 break;
16990 case widgBTNCOUNTER:
16991 ((SW_BtnCounter*)widg)->align = val;
16992 break;
16993 case widgMMAPTITLE:
16994 ((SW_MMapTitle*)widg)->align = val;
16995 break;
16996 default:
16997 bad_subwidg_type(false, ty);
16998 break;
16999 }
17000 }
17001 break;
17002 }
17003 case SUBWIDGTY_SHADOWTY:
17004 {
17005 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17006 {
17007 auto val = vbound(value/10000,0,sstsMAX-1);
17008 auto ty = widg->getType();
17009 switch(ty)
17010 {
17011 case widgTEXT:
17012 ((SW_Text*)widg)->shadtype = val;
17013 break;
17014 case widgTEXTBOX:
17015 ((SW_TextBox*)widg)->shadtype = val;
17016 break;
17017 case widgSELECTEDTEXT:
17018 ((SW_SelectedText*)widg)->shadtype = val;
17019 break;
17020 case widgTIME:
17021 ((SW_Time*)widg)->shadtype = val;
17022 break;
17023 case widgCOUNTER:
17024 ((SW_Counter*)widg)->shadtype = val;
17025 break;
17026 case widgBTNCOUNTER:
17027 ((SW_BtnCounter*)widg)->shadtype = val;
17028 break;
17029 case widgOLDCTR:
17030 ((SW_Counters*)widg)->shadtype = val;
17031 break;
17032 case widgMMAPTITLE:
17033 ((SW_MMapTitle*)widg)->shadtype = val;
17034 break;
17035 default:
17036 bad_subwidg_type(false, ty);
17037 break;
17038 }
17039 }
17040 break;
17041 }
17042 case SUBWIDGTY_COLOR_TXT:
17043 {
17044 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17045 {
17046 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17047 auto ty = widg->getType();
17048 switch(ty)
17049 {
17050 case widgTEXT:
17051 ((SW_Text*)widg)->c_text.set_int_color(val);
17052 break;
17053 case widgTEXTBOX:
17054 ((SW_TextBox*)widg)->c_text.set_int_color(val);
17055 break;
17056 case widgSELECTEDTEXT:
17057 ((SW_SelectedText*)widg)->c_text.set_int_color(val);
17058 break;
17059 case widgTIME:
17060 ((SW_Time*)widg)->c_text.set_int_color(val);
17061 break;
17062 case widgCOUNTER:
17063 ((SW_Counter*)widg)->c_text.set_int_color(val);
17064 break;
17065 case widgBTNCOUNTER:
17066 ((SW_BtnCounter*)widg)->c_text.set_int_color(val);
17067 break;
17068 case widgOLDCTR:
17069 ((SW_Counters*)widg)->c_text.set_int_color(val);
17070 break;
17071 case widgMMAPTITLE:
17072 ((SW_MMapTitle*)widg)->c_text.set_int_color(val);
17073 break;
17074 case widgMCGUFF_FRAME:
17075 ((SW_TriFrame*)widg)->c_number.set_int_color(val);
17076 break;
17077 default:
17078 bad_subwidg_type(false, ty);
17079 break;
17080 }
17081 }
17082 break;
17083 }
17084 case SUBWIDGTY_COLOR_SHD:
17085 {
17086 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17087 {
17088 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17089 auto ty = widg->getType();
17090 switch(ty)
17091 {
17092 case widgTEXT:
17093 ((SW_Text*)widg)->c_shadow.set_int_color(val);
17094 break;
17095 case widgTEXTBOX:
17096 ((SW_TextBox*)widg)->c_shadow.set_int_color(val);
17097 break;
17098 case widgSELECTEDTEXT:
17099 ((SW_SelectedText*)widg)->c_shadow.set_int_color(val);
17100 break;
17101 case widgTIME:
17102 ((SW_Time*)widg)->c_shadow.set_int_color(val);
17103 break;
17104 case widgCOUNTER:
17105 ((SW_Counter*)widg)->c_shadow.set_int_color(val);
17106 break;
17107 case widgBTNCOUNTER:
17108 ((SW_BtnCounter*)widg)->c_shadow.set_int_color(val);
17109 break;
17110 case widgOLDCTR:
17111 ((SW_Counters*)widg)->c_shadow.set_int_color(val);
17112 break;
17113 case widgMMAPTITLE:
17114 ((SW_MMapTitle*)widg)->c_shadow.set_int_color(val);
17115 break;
17116 default:
17117 bad_subwidg_type(false, ty);
17118 break;
17119 }
17120 }
17121 break;
17122 }
17123 case SUBWIDGTY_COLOR_BG:
17124 {
17125 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17126 {
17127 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17128 auto ty = widg->getType();
17129 switch(ty)
17130 {
17131 case widgTEXT:
17132 ((SW_Text*)widg)->c_bg.set_int_color(val);
17133 break;
17134 case widgTEXTBOX:
17135 ((SW_TextBox*)widg)->c_bg.set_int_color(val);;
17136 break;
17137 case widgSELECTEDTEXT:
17138 ((SW_SelectedText*)widg)->c_bg.set_int_color(val);;
17139 break;
17140 case widgTIME:
17141 ((SW_Time*)widg)->c_bg.set_int_color(val);
17142 break;
17143 case widgCOUNTER:
17144 ((SW_Counter*)widg)->c_bg.set_int_color(val);
17145 break;
17146 case widgBTNCOUNTER:
17147 ((SW_BtnCounter*)widg)->c_bg.set_int_color(val);
17148 break;
17149 case widgOLDCTR:
17150 ((SW_Counters*)widg)->c_bg.set_int_color(val);
17151 break;
17152 case widgMMAPTITLE:
17153 ((SW_MMapTitle*)widg)->c_bg.set_int_color(val);
17154 break;
17155 case widgBGCOLOR:
17156 ((SW_Clear*)widg)->c_bg.set_int_color(val);
17157 break;
17158 case widgCOUNTERPERCBAR:
17159 ((SW_CounterPercentBar*)widg)->c_bg.set_int_color(val);
17160 break;
17161 default:
17162 bad_subwidg_type(false, ty);
17163 break;
17164 }
17165 }
17166 break;
17167 }
17168
17169 case SUBWIDGTY_COLOR_TXT2:
17170 {
17171 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17172 {
17173 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17174 auto ty = widg->getType();
17175 switch(ty)
17176 {
17177 case widgCOUNTER:
17178 ((SW_Counter*)widg)->c_text2.set_int_color(val);
17179 break;
17180 case widgBTNCOUNTER:
17181 ((SW_BtnCounter*)widg)->c_text2.set_int_color(val);
17182 break;
17183 default:
17184 bad_subwidg_type(false, ty);
17185 break;
17186 }
17187 }
17188 break;
17189 }
17190 case SUBWIDGTY_COLOR_SHD2:
17191 {
17192 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17193 {
17194 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17195 auto ty = widg->getType();
17196 switch(ty)
17197 {
17198 case widgCOUNTER:
17199 ((SW_Counter*)widg)->c_shadow2.set_int_color(val);
17200 break;
17201 case widgBTNCOUNTER:
17202 ((SW_BtnCounter*)widg)->c_shadow2.set_int_color(val);
17203 break;
17204 default:
17205 bad_subwidg_type(false, ty);
17206 break;
17207 }
17208 }
17209 break;
17210 }
17211 case SUBWIDGTY_COLOR_BG2:
17212 {
17213 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17214 {
17215 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17216 auto ty = widg->getType();
17217 switch(ty)
17218 {
17219 case widgCOUNTER:
17220 ((SW_Counter*)widg)->c_bg2.set_int_color(val);
17221 break;
17222 case widgBTNCOUNTER:
17223 ((SW_BtnCounter*)widg)->c_bg2.set_int_color(val);
17224 break;
17225 default:
17226 bad_subwidg_type(false, ty);
17227 break;
17228 }
17229 }
17230 break;
17231 }
17232
17233 case SUBWIDGTY_COLOR_OLINE:
17234 {
17235 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17236 {
17237 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17238 auto ty = widg->getType();
17239 switch(ty)
17240 {
17241 case widgLINE:
17242 ((SW_Line*)widg)->c_line.set_int_color(val);
17243 break;
17244 case widgRECT:
17245 ((SW_Rect*)widg)->c_outline.set_int_color(val);
17246 break;
17247 case widgMCGUFF_FRAME:
17248 ((SW_TriFrame*)widg)->c_outline.set_int_color(val);
17249 break;
17250 default:
17251 bad_subwidg_type(false, ty);
17252 break;
17253 }
17254 }
17255 break;
17256 }
17257
17258 case SUBWIDGTY_COLOR_FILL:
17259 {
17260 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17261 {
17262 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17263 auto ty = widg->getType();
17264 switch(ty)
17265 {
17266 case widgRECT:
17267 ((SW_Rect*)widg)->c_fill.set_int_color(val);
17268 break;
17269 case widgCOUNTERPERCBAR:
17270 ((SW_CounterPercentBar*)widg)->c_fill.set_int_color(val);
17271 break;
17272 default:
17273 bad_subwidg_type(false, ty);
17274 break;
17275 }
17276 }
17277 break;
17278 }
17279 case SUBWIDGTY_BUTTON:
17280 {
17281 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17282 {
17283 auto val = vbound(value/10000,0,3);
17284 auto ty = widg->getType();
17285 switch(ty)
17286 {
17287 case widgBTNITM:
17288 ((SW_ButtonItem*)widg)->btn = val;
17289 break;
17290 case widgBTNCOUNTER:
17291 ((SW_BtnCounter*)widg)->btn = val;
17292 break;
17293 default:
17294 bad_subwidg_type(false, ty);
17295 break;
17296 }
17297 }
17298 break;
17299 }
17300 case SUBWIDGTY_MINDIG:
17301 {
17302 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17303 {
17304 auto val = vbound(value/10000,0,5);
17305 auto ty = widg->getType();
17306 switch(ty)
17307 {
17308 case widgCOUNTER:
17309 ((SW_Counter*)widg)->mindigits = val;
17310 break;
17311 case widgBTNCOUNTER:
17312 ((SW_BtnCounter*)widg)->mindigits = val;
17313 break;
17314 case widgOLDCTR:
17315 ((SW_Counters*)widg)->digits = val;
17316 break;
17317 default:
17318 bad_subwidg_type(false, ty);
17319 break;
17320 }
17321 }
17322 break;
17323 }
17324 case SUBWIDGTY_MAXDIG:
17325 {
17326 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17327 {
17328 auto val = vbound(value/10000,0,5);
17329 auto ty = widg->getType();
17330 switch(ty)
17331 {
17332 case widgCOUNTER:
17333 ((SW_Counter*)widg)->maxdigits = val;
17334 break;
17335 case widgBTNCOUNTER:
17336 ((SW_BtnCounter*)widg)->maxdigits = val;
17337 break;
17338 default:
17339 bad_subwidg_type(false, ty);
17340 break;
17341 }
17342 }
17343 break;
17344 }
17345 case SUBWIDGTY_INFITM:
17346 {
17347 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17348 {
17349 auto val = vbound(value/10000,-1,MAXITEMS-1);
17350 auto ty = widg->getType();
17351 switch(ty)
17352 {
17353 case widgCOUNTER:
17354 ((SW_Counter*)widg)->infitm = val;
17355 break;
17356 case widgOLDCTR:
17357 ((SW_Counters*)widg)->infitm = val;
17358 break;
17359 case widgLGAUGE:
17360 case widgMGAUGE:
17361 case widgMISCGAUGE:
17362 ((SW_GaugePiece*)widg)->inf_item = val;
17363 break;
17364 default:
17365 bad_subwidg_type(false, ty);
17366 break;
17367 }
17368 }
17369 break;
17370 }
17371 case SUBWIDGTY_INFCHAR:
17372 {
17373 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17374 {
17375 char val = vbound(value/10000,0,255);
17376 auto ty = widg->getType();
17377 switch(ty)
17378 {
17379 case widgCOUNTER:
17380 ((SW_Counter*)widg)->infchar = val;
17381 break;
17382 case widgBTNCOUNTER:
17383 ((SW_BtnCounter*)widg)->infchar = val;
17384 break;
17385 case widgOLDCTR:
17386 ((SW_Counters*)widg)->infchar = val;
17387 break;
17388 default:
17389 bad_subwidg_type(false, ty);
17390 break;
17391 }
17392 }
17393 break;
17394 }
17395 case SUBWIDGTY_COSTIND:
17396 {
17397 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17398 {
17399 auto val = vbound(value/10000,0,1);
17400 auto ty = widg->getType();
17401 switch(ty)
17402 {
17403 case widgBTNCOUNTER:
17404 ((SW_BtnCounter*)widg)->costind = val;
17405 break;
17406 default:
17407 bad_subwidg_type(false, ty);
17408 break;
17409 }
17410 }
17411 break;
17412 }
17413 case SUBWIDGTY_COLOR_PLAYER:
17414 {
17415 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17416 {
17417 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17418 auto ty = widg->getType();
17419 switch(ty)
17420 {
17421 case widgMMAP:
17422 ((SW_MMap*)widg)->c_plr.set_int_color(val);
17423 break;
17424 case widgLMAP:
17425 ((SW_LMap*)widg)->c_plr.set_int_color(val);
17426 break;
17427 default:
17428 bad_subwidg_type(false, ty);
17429 break;
17430 }
17431 }
17432 break;
17433 }
17434 case SUBWIDGTY_COLOR_CMPBLNK:
17435 {
17436 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17437 {
17438 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17439 auto ty = widg->getType();
17440 switch(ty)
17441 {
17442 case widgMMAP:
17443 ((SW_MMap*)widg)->c_cmp_blink.set_int_color(val);
17444 break;
17445 default:
17446 bad_subwidg_type(false, ty);
17447 break;
17448 }
17449 }
17450 break;
17451 }
17452 case SUBWIDGTY_COLOR_CMPOFF:
17453 {
17454 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17455 {
17456 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17457 auto ty = widg->getType();
17458 switch(ty)
17459 {
17460 case widgMMAP:
17461 ((SW_MMap*)widg)->c_cmp_off.set_int_color(val);
17462 break;
17463 default:
17464 bad_subwidg_type(false, ty);
17465 break;
17466 }
17467 }
17468 break;
17469 }
17470 case SUBWIDGTY_COLOR_ROOM:
17471 {
17472 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17473 {
17474 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17475 auto ty = widg->getType();
17476 switch(ty)
17477 {
17478 case widgLMAP:
17479 ((SW_LMap*)widg)->c_room.set_int_color(val);
17480 break;
17481 default:
17482 bad_subwidg_type(false, ty);
17483 break;
17484 }
17485 }
17486 break;
17487 }
17488 case SUBWIDGTY_ITEMCLASS:
17489 {
17490 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17491 {
17492 auto val = vbound(value/10000,0,itype_maxusable-1);
17493 auto ty = widg->getType();
17494 switch(ty)
17495 {
17496 case widgITEMSLOT:
17497 ((SW_ItemSlot*)widg)->iclass = val;
17498 break;
17499 default:
17500 bad_subwidg_type(false, ty);
17501 break;
17502 }
17503 }
17504 break;
17505 }
17506 case SUBWIDGTY_ITEMID:
17507 {
17508 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17509 {
17510 auto val = vbound(value/10000,-1,MAXITEMS-1);
17511 auto ty = widg->getType();
17512 switch(ty)
17513 {
17514 case widgITEMSLOT:
17515 ((SW_ItemSlot*)widg)->iid = val;
17516 break;
17517 default:
17518 bad_subwidg_type(false, ty);
17519 break;
17520 }
17521 }
17522 break;
17523 }
17524 case SUBWIDGTY_FRAMETILE:
17525 {
17526 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17527 {
17528 auto val = vbound(value/10000,0,NEWMAXTILES-1);
17529 auto ty = widg->getType();
17530 switch(ty)
17531 {
17532 case widgMCGUFF_FRAME:
17533 ((SW_TriFrame*)widg)->frame_tile = val;
17534 break;
17535 default:
17536 bad_subwidg_type(false, ty);
17537 break;
17538 }
17539 }
17540 break;
17541 }
17542 case SUBWIDGTY_FRAMECSET:
17543 {
17544 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17545 {
17546 auto val = vbound(value/10000,0,15);
17547 auto ty = widg->getType();
17548 switch(ty)
17549 {
17550 case widgMCGUFF_FRAME:
17551 ((SW_TriFrame*)widg)->frame_cset = val;
17552 break;
17553 default:
17554 bad_subwidg_type(false, ty);
17555 break;
17556 }
17557 }
17558 break;
17559 }
17560 case SUBWIDGTY_PIECETILE:
17561 {
17562 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17563 {
17564 auto val = vbound(value/10000,0,NEWMAXTILES-1);
17565 auto ty = widg->getType();
17566 switch(ty)
17567 {
17568 case widgMCGUFF_FRAME:
17569 ((SW_TriFrame*)widg)->piece_tile = val;
17570 break;
17571 default:
17572 bad_subwidg_type(false, ty);
17573 break;
17574 }
17575 }
17576 break;
17577 }
17578 case SUBWIDGTY_PIECECSET:
17579 {
17580 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17581 {
17582 auto val = vbound(value/10000,0,15);
17583 auto ty = widg->getType();
17584 switch(ty)
17585 {
17586 case widgMCGUFF_FRAME:
17587 ((SW_TriFrame*)widg)->piece_cset = val;
17588 break;
17589 default:
17590 bad_subwidg_type(false, ty);
17591 break;
17592 }
17593 }
17594 break;
17595 }
17596 case SUBWIDGTY_FLIP:
17597 {
17598 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17599 {
17600 auto val = vbound(value/10000,0,15);
17601 auto ty = widg->getType();
17602 switch(ty)
17603 {
17604 case widgMCGUFF:
17605 ((SW_McGuffin*)widg)->flip = val;
17606 break;
17607 case widgTILEBLOCK:
17608 ((SW_TileBlock*)widg)->flip = val;
17609 break;
17610 case widgMINITILE:
17611 ((SW_MiniTile*)widg)->flip = val;
17612 break;
17613 default:
17614 bad_subwidg_type(false, ty);
17615 break;
17616 }
17617 }
17618 break;
17619 }
17620 case SUBWIDGTY_NUMBER:
17621 {
17622 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17623 {
17624 auto val = vbound(value/10000,0,255);
17625 auto ty = widg->getType();
17626 switch(ty)
17627 {
17628 case widgMCGUFF:
17629 ((SW_McGuffin*)widg)->number = val;
17630 break;
17631 default:
17632 bad_subwidg_type(false, ty);
17633 break;
17634 }
17635 }
17636 break;
17637 }
17638 case SUBWIDGTY_FRAMES:
17639 {
17640 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17641 {
17642 auto val = vbound(value/10000,1,65535);
17643 auto ty = widg->getType();
17644 switch(ty)
17645 {
17646 case widgLGAUGE:
17647 case widgMGAUGE:
17648 case widgMISCGAUGE:
17649 ((SW_GaugePiece*)widg)->frames = val;
17650 break;
17651 default:
17652 bad_subwidg_type(false, ty);
17653 break;
17654 }
17655 }
17656 break;
17657 }
17658 case SUBWIDGTY_SPEED:
17659 {
17660 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17661 {
17662 auto val = vbound(value/10000,1,65535);
17663 auto ty = widg->getType();
17664 switch(ty)
17665 {
17666 case widgLGAUGE:
17667 case widgMGAUGE:
17668 case widgMISCGAUGE:
17669 ((SW_GaugePiece*)widg)->speed = val;
17670 break;
17671 default:
17672 bad_subwidg_type(false, ty);
17673 break;
17674 }
17675 }
17676 break;
17677 }
17678 case SUBWIDGTY_DELAY:
17679 {
17680 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17681 {
17682 auto val = vbound(value/10000,0,65535);
17683 auto ty = widg->getType();
17684 switch(ty)
17685 {
17686 case widgLGAUGE:
17687 case widgMGAUGE:
17688 case widgMISCGAUGE:
17689 ((SW_GaugePiece*)widg)->delay = val;
17690 break;
17691 default:
17692 bad_subwidg_type(false, ty);
17693 break;
17694 }
17695 }
17696 break;
17697 }
17698 case SUBWIDGTY_CONTAINER:
17699 {
17700 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17701 {
17702 auto val = vbound(value/10000,0,65535);
17703 auto ty = widg->getType();
17704 switch(ty)
17705 {
17706 case widgLGAUGE:
17707 case widgMGAUGE:
17708 case widgMISCGAUGE:
17709 ((SW_GaugePiece*)widg)->container = val;
17710 break;
17711 default:
17712 bad_subwidg_type(false, ty);
17713 break;
17714 }
17715 }
17716 break;
17717 }
17718 case SUBWIDGTY_GAUGE_WID:
17719 {
17720 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17721 {
17722 auto val = vbound(value/10000,1,32)-1;
17723 auto ty = widg->getType();
17724 switch(ty)
17725 {
17726 case widgLGAUGE:
17727 case widgMGAUGE:
17728 case widgMISCGAUGE:
17729 ((SW_GaugePiece*)widg)->gauge_wid = val;
17730 break;
17731 default:
17732 bad_subwidg_type(false, ty);
17733 break;
17734 }
17735 }
17736 break;
17737 }
17738 case SUBWIDGTY_GAUGE_HEI:
17739 {
17740 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17741 {
17742 auto val = vbound(value/10000,1,32)-1;
17743 auto ty = widg->getType();
17744 switch(ty)
17745 {
17746 case widgLGAUGE:
17747 case widgMGAUGE:
17748 case widgMISCGAUGE:
17749 ((SW_GaugePiece*)widg)->gauge_hei = val;
17750 break;
17751 default:
17752 bad_subwidg_type(false, ty);
17753 break;
17754 }
17755 }
17756 break;
17757 }
17758 case SUBWIDGTY_UNITS:
17759 {
17760 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17761 {
17762 auto val = vbound(value/10000,1,256);
17763 auto ty = widg->getType();
17764 switch(ty)
17765 {
17766 case widgLGAUGE:
17767 case widgMGAUGE:
17768 case widgMISCGAUGE:
17769 ((SW_GaugePiece*)widg)->unit_per_frame = val-1;
17770 break;
17771 default:
17772 bad_subwidg_type(false, ty);
17773 break;
17774 }
17775 }
17776 break;
17777 }
17778 case SUBWIDGTY_HSPACE:
17779 {
17780 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17781 {
17782 auto val = vbound(value/10000,-128,127);
17783 auto ty = widg->getType();
17784 switch(ty)
17785 {
17786 case widgLGAUGE:
17787 case widgMGAUGE:
17788 case widgMISCGAUGE:
17789 ((SW_GaugePiece*)widg)->hspace = val;
17790 break;
17791 default:
17792 bad_subwidg_type(false, ty);
17793 break;
17794 }
17795 }
17796 break;
17797 }
17798 case SUBWIDGTY_VSPACE:
17799 {
17800 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17801 {
17802 auto val = vbound(value/10000,-128,127);
17803 auto ty = widg->getType();
17804 switch(ty)
17805 {
17806 case widgLGAUGE:
17807 case widgMGAUGE:
17808 case widgMISCGAUGE:
17809 ((SW_GaugePiece*)widg)->vspace = val;
17810 break;
17811 default:
17812 bad_subwidg_type(false, ty);
17813 break;
17814 }
17815 }
17816 break;
17817 }
17818 case SUBWIDGTY_GRIDX:
17819 {
17820 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17821 {
17822 auto val = vbound(value/10000,-32768,32767);
17823 auto ty = widg->getType();
17824 switch(ty)
17825 {
17826 case widgLGAUGE:
17827 case widgMGAUGE:
17828 case widgMISCGAUGE:
17829 ((SW_GaugePiece*)widg)->grid_xoff = val;
17830 break;
17831 default:
17832 bad_subwidg_type(false, ty);
17833 break;
17834 }
17835 }
17836 break;
17837 }
17838 case SUBWIDGTY_GRIDY:
17839 {
17840 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17841 {
17842 auto val = vbound(value/10000,-32768,32767);
17843 auto ty = widg->getType();
17844 switch(ty)
17845 {
17846 case widgLGAUGE:
17847 case widgMGAUGE:
17848 case widgMISCGAUGE:
17849 ((SW_GaugePiece*)widg)->grid_yoff = val;
17850 break;
17851 default:
17852 bad_subwidg_type(false, ty);
17853 break;
17854 }
17855 }
17856 break;
17857 }
17858 case SUBWIDGTY_ANIMVAL:
17859 {
17860 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17861 {
17862 auto val = vbound(value/10000,0,65535);
17863 auto ty = widg->getType();
17864 switch(ty)
17865 {
17866 case widgLGAUGE:
17867 case widgMGAUGE:
17868 case widgMISCGAUGE:
17869 ((SW_GaugePiece*)widg)->anim_val = val;
17870 break;
17871 default:
17872 bad_subwidg_type(false, ty);
17873 break;
17874 }
17875 }
17876 break;
17877 }
17878 case SUBWIDGTY_SHOWDRAIN:
17879 {
17880 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17881 {
17882 auto val = vbound(value/10000,-1,32767);
17883 auto ty = widg->getType();
17884 switch(ty)
17885 {
17886 case widgMGAUGE:
17887 ((SW_MagicGaugePiece*)widg)->showdrain = val;
17888 break;
17889 default:
17890 bad_subwidg_type(false, ty);
17891 break;
17892 }
17893 }
17894 break;
17895 }
17896 case SUBWIDGTY_PERCONTAINER:
17897 {
17898 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17899 {
17900 auto val = vbound(value/10000,1,65535);
17901 auto ty = widg->getType();
17902 switch(ty)
17903 {
17904 case widgMISCGAUGE:
17905 ((SW_MiscGaugePiece*)widg)->per_container = val;
17906 break;
17907 default:
17908 bad_subwidg_type(false, ty);
17909 break;
17910 }
17911 }
17912 break;
17913 }
17914 case SUBWIDGTY_TABSIZE:
17915 {
17916 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17917 {
17918 auto val = vbound(value/10000,0,255);
17919 auto ty = widg->getType();
17920 switch(ty)
17921 {
17922 case widgTEXTBOX:
17923 ((SW_TextBox*)widg)->tabsize = val;
17924 break;
17925 case widgSELECTEDTEXT:
17926 ((SW_SelectedText*)widg)->tabsize = val;
17927 break;
17928 default:
17929 bad_subwidg_type(false, ty);
17930 break;
17931 }
17932 }
17933 break;
17934 }
17935 case SUBWIDGTY_LITEMS:
17936 {
17937 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17938 {
17939 auto val = vbound(value/10000,0,255);
17940 auto ty = widg->getType();
17941 switch(ty)
17942 {
17943 case widgMMAP:
17944 ((SW_MMap*)widg)->compass_litems = val;
17945 break;
17946 default:
17947 bad_subwidg_type(false, ty);
17948 break;
17949 }
17950 }
17951 break;
17952 }
17953
17954 default:
17955 {
17956
2/2
✓ Branch 0 taken 17300215 times.
✓ Branch 1 taken 26483010 times.
43783225 if (zasm_array_supports(arg))
17957 {
17958 17300215 int ref_arg = get_register_ref_dependency(arg).value_or(0);
17959
2/2
✓ Branch 0 taken 9336816 times.
✓ Branch 1 taken 7963399 times.
17300215 int ref = ref_arg ? get_ref(ref_arg) : 0;
17960 17300215 zasm_array_set(arg, ref, ri->d[rINDEX] / 10000, value);
17961 17300215 }
17962 else
17963 {
17964 26483010 scripting_engine_set_register(arg, value);
17965 }
17966 }
17967 43783225 }
17968
17969 1623090814 current_zasm_register = 0;
17970 5946899392 } //end set_register
17971
17972 412 static std::map<std::string, int> name_to_slot_index_ffcmap;
17973 412 static std::map<std::string, int> name_to_slot_index_globalmap;
17974 412 static std::map<std::string, int> name_to_slot_index_genericmap;
17975 412 static std::map<std::string, int> name_to_slot_index_itemmap;
17976 412 static std::map<std::string, int> name_to_slot_index_npcmap;
17977 412 static std::map<std::string, int> name_to_slot_index_ewpnmap;
17978 412 static std::map<std::string, int> name_to_slot_index_lwpnmap;
17979 412 static std::map<std::string, int> name_to_slot_index_playermap;
17980 412 static std::map<std::string, int> name_to_slot_index_dmapmap;
17981 412 static std::map<std::string, int> name_to_slot_index_screenmap;
17982 412 static std::map<std::string, int> name_to_slot_index_itemspritemap;
17983 412 static std::map<std::string, int> name_to_slot_index_comboscriptmap;
17984 412 static std::map<std::string, int> name_to_slot_index_subscreenmap;
17985
17986 422 void script_init_name_to_slot_index_maps()
17987 {
17988 int i;
17989 #define DECL_INIT_MAP(name) \
17990 {\
17991 name_to_slot_index_##name.clear();\
17992 i = 0;\
17993 for (auto& it : name)\
17994 {\
17995 if (!name_to_slot_index_##name.contains(it.second.scriptname))\
17996 name_to_slot_index_##name[it.second.scriptname] = i;\
17997 i++;\
17998 }\
17999 }
18000
18001
4/4
✓ Branch 0 taken 215642 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 206149 times.
✓ Branch 3 taken 9493 times.
216064 DECL_INIT_MAP(ffcmap);
18002
4/4
✓ Branch 0 taken 3376 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 1968 times.
✓ Branch 3 taken 1408 times.
3798 DECL_INIT_MAP(globalmap);
18003
4/4
✓ Branch 0 taken 215642 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 213072 times.
✓ Branch 3 taken 2570 times.
216064 DECL_INIT_MAP(genericmap);
18004
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 106112 times.
✓ Branch 3 taken 1498 times.
108032 DECL_INIT_MAP(itemmap);
18005
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 107173 times.
✓ Branch 3 taken 437 times.
108032 DECL_INIT_MAP(npcmap);
18006
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 107039 times.
✓ Branch 3 taken 571 times.
108032 DECL_INIT_MAP(ewpnmap);
18007
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 106957 times.
✓ Branch 3 taken 653 times.
108032 DECL_INIT_MAP(lwpnmap);
18008
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 1251 times.
✓ Branch 3 taken 437 times.
2110 DECL_INIT_MAP(playermap);
18009
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 106777 times.
✓ Branch 3 taken 833 times.
108032 DECL_INIT_MAP(dmapmap);
18010
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 106852 times.
✓ Branch 3 taken 758 times.
108032 DECL_INIT_MAP(screenmap);
18011
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 107163 times.
✓ Branch 3 taken 447 times.
108032 DECL_INIT_MAP(itemspritemap);
18012
4/4
✓ Branch 0 taken 215642 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 215131 times.
✓ Branch 3 taken 511 times.
216064 DECL_INIT_MAP(comboscriptmap);
18013
4/4
✓ Branch 0 taken 107610 times.
✓ Branch 1 taken 422 times.
✓ Branch 2 taken 107182 times.
✓ Branch 3 taken 428 times.
108032 DECL_INIT_MAP(subscreenmap);
18014 422 }
18015
18016 10246331 static void do_get_script_index_by_name(const std::map<std::string, int>& name_to_slot_index)
18017 {
18018 10246331 int32_t arrayptr = get_register(sarg1);
18019 10246331 string name;
18020 10246331 int32_t num=-1;
18021
1/2
✓ Branch 0 taken 10246331 times.
✗ Branch 1 not taken.
10246331 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
18022
18023
1/2
✓ Branch 0 taken 10246331 times.
✗ Branch 1 not taken.
10246331 auto it = name_to_slot_index.find(name);
18024
2/2
✓ Branch 0 taken 8430579 times.
✓ Branch 1 taken 1815752 times.
10246331 if (it != name_to_slot_index.end())
18025 1815752 num = it->second + 1;
18026
18027
1/2
✓ Branch 0 taken 10246331 times.
✗ Branch 1 not taken.
10246331 set_register(sarg1, num * 10000);
18028 10246331 }
18029
18030 int32_t legacy_get_int_arr(const int32_t ptr, int32_t indx)
18031 {
18032 switch(ptr)
18033 {
18034 case INTARR_SCREEN_NPC:
18035 {
18036 current_zasm_context = "Screen->NPCs[]";
18037 if(BC::checkGuyIndex(indx) != SH::_NoError)
18038 return 0;
18039 current_zasm_context = "";
18040
18041 return guys.spr(indx)->getUID();
18042 }
18043 case INTARR_SCREEN_ITEMSPR:
18044 {
18045 current_zasm_context = "Screen->Items[]";
18046 if(BC::checkItemIndex(indx) != SH::_NoError)
18047 return 0;
18048 current_zasm_context = "";
18049
18050 return items.spr(indx)->getUID();
18051 }
18052 case INTARR_SCREEN_LWPN:
18053 {
18054 current_zasm_context = "Screen->LWeapons[]";
18055 if(BC::checkLWeaponIndex(indx) != SH::_NoError)
18056 return 0;
18057 current_zasm_context = "";
18058
18059 return Lwpns.spr(indx)->getUID();
18060 }
18061 case INTARR_SCREEN_EWPN:
18062 {
18063 current_zasm_context = "Screen->EWeapons[]";
18064 if(BC::checkEWeaponIndex(indx) != SH::_NoError)
18065 return 0;
18066 current_zasm_context = "";
18067
18068 return Ewpns.spr(indx)->getUID();
18069 }
18070 case INTARR_SCREEN_FFC:
18071 {
18072 current_zasm_context = "Screen->FFCs[]";
18073 if (auto ffc = ResolveFFCWithID(indx))
18074 {
18075 current_zasm_context = "";
18076
18077 if (ZScriptVersion::ffcRefIsSpriteId())
18078 return ffc->getUID();
18079
18080 return indx * 10000;
18081 }
18082
18083 return 0;
18084 }
18085 case INTARR_SCREEN_PORTALS:
18086 {
18087 current_zasm_context = "Screen->Portals[]";
18088 if(BC::checkBoundsOneIndexed(indx, 0, portals.Count()-1) != SH::_NoError)
18089 return 0;
18090 current_zasm_context = "";
18091
18092 return portals.spr(indx)->getUID();
18093 }
18094 case INTARR_SAVPRTL:
18095 {
18096 current_zasm_context = "Game->SavedPortals[]";
18097 if(BC::checkBoundsOneIndexed(indx, 0, game->user_portals.size()-1) != SH::_NoError)
18098 return 0;
18099 current_zasm_context = "";
18100
18101 return (indx+1)*10000;
18102 }
18103 default:
18104 {
18105 scripting_log_error_with_context("Unknown internal array '{}' read from!", ptr);
18106 return 0;
18107 }
18108 }
18109 }
18110 void legacy_set_int_arr(const int32_t ptr, int32_t indx, int32_t val)
18111 {
18112 switch(ptr)
18113 {
18114 case INTARR_SCREEN_NPC:
18115 scripting_log_error_with_context("Read-only array 'Screen->NPCs' cannot be written to!");
18116 return;
18117 case INTARR_SCREEN_ITEMSPR:
18118 scripting_log_error_with_context("Read-only array 'Screen->Items' cannot be written to!");
18119 return;
18120 case INTARR_SCREEN_LWPN:
18121 scripting_log_error_with_context("Read-only array 'Screen->LWeapons' cannot be written to!");
18122 return;
18123 case INTARR_SCREEN_EWPN:
18124 scripting_log_error_with_context("Read-only array 'Screen->EWeapons' cannot be written to!");
18125 return;
18126 case INTARR_SCREEN_FFC:
18127 scripting_log_error_with_context("Read-only array 'Screen->FFCs' cannot be written to!");
18128 return;
18129 case INTARR_SCREEN_PORTALS:
18130 scripting_log_error_with_context("Read-only array 'Screen->Portals' cannot be written to!");
18131 return;
18132 case INTARR_SAVPRTL:
18133 scripting_log_error_with_context("Read-only array 'Game->SavedPortals' cannot be written to!");
18134 return;
18135
18136 default:
18137 {
18138 scripting_log_error_with_context("Unknown internal array '{}' written to!", ptr);
18139 return;
18140 }
18141 }
18142 }
18143 int32_t legacy_sz_int_arr(const int32_t ptr)
18144 {
18145 switch(ptr)
18146 {
18147 case INTARR_SCREEN_NPC:
18148 {
18149 return guys.Count();
18150 }
18151 case INTARR_SCREEN_ITEMSPR:
18152 {
18153 return items.Count();
18154 }
18155 case INTARR_SCREEN_LWPN:
18156 {
18157 return Lwpns.Count();
18158 }
18159 case INTARR_SCREEN_EWPN:
18160 {
18161 return Ewpns.Count();
18162 }
18163 case INTARR_SCREEN_FFC:
18164 {
18165 return MAXFFCS;
18166 }
18167 case INTARR_SCREEN_PORTALS:
18168 {
18169 return portals.Count();
18170 }
18171 case INTARR_SAVPRTL:
18172 {
18173 return game->user_portals.size();
18174 }
18175 default:
18176 {
18177 scripting_log_error_with_context("Unknown internal array '{}' size read!", ptr);
18178 return -1;
18179 }
18180 }
18181 }
18182
18183 ///----------------------------------------------------------------------------------------------------//
18184 // ASM Functions //
18185 ///----------------------------------------------------------------------------------------------------//
18186
18187 12229747 bool check_stack(uint32_t sp)
18188 {
18189
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 12229746 times.
12229747 if (sp >= MAX_STACK_SIZE)
18190 {
18191 1 log_stack_overflow_error();
18192 1 ri->overflow = true;
18193 1 return false;
18194 }
18195
18196 12229746 return true;
18197 12229747 }
18198
18199 209313780 void retstack_push(int32_t val)
18200 {
18201
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 209313779 times.
209313780 if(ri->retsp >= ret_stack->size())
18202 {
18203 1 log_call_limit_error();
18204 1 ri->overflow = true;
18205 1 return;
18206 }
18207 209313779 ret_stack->at(ri->retsp++) = val;
18208 209313780 }
18209 209294241 optional<int32_t> retstack_pop()
18210 {
18211
2/2
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 209293431 times.
209294241 if(!ri->retsp)
18212 810 return nullopt; //return from root, so, QUIT
18213 209293431 return ret_stack->at(--ri->retsp);
18214 209294241 }
18215
18216 1392882380 void stack_push(int32_t val)
18217 {
18218 1392882380 SH::write_stack(--ri->sp, val);
18219 1392882380 }
18220 12229747 void stack_push(int32_t val, size_t count)
18221 {
18222
2/2
✓ Branch 0 taken 12229746 times.
✓ Branch 1 taken 1 times.
12229747 if (!check_stack(ri->sp - count))
18223 1 return;
18224
18225
2/2
✓ Branch 0 taken 12229746 times.
✓ Branch 1 taken 48125606 times.
60355352 for(int q = 0; q < count; ++q)
18226 {
18227 48125606 --ri->sp;
18228 48125606 (*stack)[ri->sp] = val;
18229 48125606 }
18230 12229747 }
18231
18232 1236034762 int32_t stack_pop()
18233 {
18234 1236034762 const int32_t val = SH::read_stack(ri->sp);
18235 1236034762 ++ri->sp;
18236 1236034762 return val;
18237 }
18238 44520347 int32_t stack_pop(size_t count)
18239 {
18240 44520347 ri->sp += count;
18241 44520347 const int32_t val = SH::read_stack(ri->sp-1);
18242 44520347 return val;
18243 }
18244
18245 ///----------------------------------------------------------------------------------------------------//
18246 //Internal (to ZScript)
18247
18248 // Changing the script of the currently executing scriptable object is not supported.
18249 1096985717 bool is_guarded_script_register(int reg)
18250 {
18251
2/2
✓ Branch 0 taken 1096903105 times.
✓ Branch 1 taken 82612 times.
1096985717 switch (reg)
18252 {
18253 case DMAPSCRIPT:
18254 case EWPNSCRIPT:
18255 case FFSCRIPT:
18256 case IDATAPSCRIPT:
18257 case IDATASCRIPT:
18258 case ITEMSPRITESCRIPT:
18259 case LWPNSCRIPT:
18260 case NPCSCRIPT:
18261 case SCREENSCRIPT:
18262 82612 return true;
18263 }
18264
18265 1096903105 return false;
18266 1096985717 }
18267
18268 1095323119 void do_set(int reg, int value)
18269 {
18270
2/2
✓ Branch 0 taken 1095242579 times.
✓ Branch 1 taken 80540 times.
1095323119 if (!is_guarded_script_register(reg))
18271 {
18272 1095242579 set_register(reg, value);
18273 1095242579 return;
18274 }
18275
18276 80540 ScriptType whichType = curScriptType;
18277 80540 int32_t whichUID = curScriptIndex;
18278
18279 80540 bool allowed = true;
18280
7/9
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 59781 times.
✓ Branch 2 taken 13218 times.
✓ Branch 3 taken 5093 times.
✓ Branch 4 taken 1410 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 975 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 37 times.
80540 switch(whichType) //Check for objects attempting to change own script
18281 {
18282 //case ScriptType::Global:
18283
18284 case ScriptType::FFC:
18285
2/2
✓ Branch 0 taken 1740 times.
✓ Branch 1 taken 3353 times.
5093 if (reg == FFSCRIPT)
18286 {
18287
3/4
✓ Branch 0 taken 3353 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3185 times.
✓ Branch 3 taken 168 times.
3353 if (auto ffc = ResolveFFC(ri->ffcref); ffc && ffc->index == whichUID)
18288 168 allowed = false;
18289 3353 }
18290 5093 break;
18291
18292 case ScriptType::Screen:
18293
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(reg==SCREENSCRIPT) //Only 1 screen script running at a time, no UID check needed
18294 allowed = false;
18295 26 break;
18296
18297 case ScriptType::Item:
18298 {
18299
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 1312 times.
1410 bool collect = ( ( whichUID < 1 ) || (whichUID == COLLECT_SCRIPT_ITEM_ZERO) );
18300
3/4
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 1312 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
1410 int32_t new_UID = ( collect ) ? (( whichUID != COLLECT_SCRIPT_ITEM_ZERO ) ? (whichUID * -1) : 0) : whichUID;
18301
18302
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 1312 times.
1410 if(collect)
18303 {
18304
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
98 if(reg==IDATAPSCRIPT && ri->idata==new_UID)
18305 allowed = false;
18306 98 }
18307
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1312 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1312 else if(reg==IDATASCRIPT && ri->idata==new_UID)
18308 allowed = false;
18309 1410 break;
18310 }
18311
18312 case ScriptType::Lwpn:
18313
3/4
✓ Branch 0 taken 59757 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 59757 times.
✗ Branch 3 not taken.
59781 if(reg==LWPNSCRIPT && ri->lwpn==whichUID)
18314 allowed = false;
18315 59781 break;
18316
18317 case ScriptType::NPC:
18318 if(reg==NPCSCRIPT && ri->guyref==whichUID)
18319 allowed = false;
18320 break;
18321
18322 case ScriptType::Ewpn:
18323
3/4
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 699 times.
✓ Branch 2 taken 276 times.
✗ Branch 3 not taken.
975 if(reg==EWPNSCRIPT && ri->ewpn==whichUID)
18324 allowed = false;
18325 975 break;
18326
18327 case ScriptType::DMap:
18328 if(reg==DMAPSCRIPT && ri->dmapsref==whichUID)
18329 allowed = false;
18330 break;
18331
18332 case ScriptType::ItemSprite:
18333
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
37 if(reg==ITEMSPRITESCRIPT && ri->itemref==whichUID)
18334 allowed = false;
18335 37 break;
18336 }
18337
18338
2/2
✓ Branch 0 taken 80372 times.
✓ Branch 1 taken 168 times.
80540 if (!allowed)
18339 {
18340 168 Z_scripterrlog("Script attempted to change own object's script! This has been ignored.\n");
18341 168 return;
18342 }
18343
18344 80372 set_register(reg, value);
18345 1095323119 }
18346
18347 1095247101 void do_set_command(const bool v)
18348 {
18349 1095247101 int32_t temp = SH::get_arg(sarg2, v);
18350 1095247101 do_set(sarg1, temp);
18351 1095247101 }
18352
18353 1392882380 void do_push(const bool v)
18354 {
18355 1392882380 const int32_t value = SH::get_arg(sarg1, v);
18356 1392882380 stack_push(value);
18357 1392882380 }
18358 3381237 void do_push_varg(const bool v)
18359 {
18360 3381237 const int32_t value = SH::get_arg(sarg1, v);
18361 3381237 zs_vargs.push_back(value);
18362 3381237 }
18363
18364 2674 void do_push_vargs(const bool v)
18365 {
18366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2674 times.
2674 if(sarg2 < 1) return;
18367 2674 const int value = SH::get_arg(sarg1, v);
18368 2674 zs_vargs.insert(zs_vargs.end(), sarg2, value);
18369 2674 zs_vargs.push_back(value);
18370 2674 }
18371
18372 1236034762 void do_pop()
18373 {
18374 1236034762 set_register(sarg1, stack_pop());
18375 1236034762 }
18376
18377 69310 void do_peek()
18378 {
18379 69310 set_register(sarg1, SH::read_stack(ri->sp));
18380 69310 }
18381
18382 void do_peekat(const bool v)
18383 {
18384 auto offs = SH::get_arg(sarg2,v);
18385 set_register(sarg1, SH::read_stack(ri->sp+offs));
18386 }
18387
18388 98846 void do_writeat(const bool v1, const bool v2)
18389 {
18390 98846 auto val = SH::get_arg(sarg1,v1);
18391 98846 auto offs = SH::get_arg(sarg2,v2);
18392 98846 SH::write_stack(ri->sp+offs, val);
18393 98846 }
18394
18395 44520347 void do_pops() // Pop past a bunch of stuff at once. Useful for clearing the stack.
18396 {
18397 44520347 set_register(sarg1, stack_pop(sarg2));
18398 44520347 }
18399
18400 12229747 void do_pushs(const bool v) // Push a bunch of the same thing. Useful for filling the stack.
18401 {
18402 12229747 const int value = SH::get_arg(sarg1, v);
18403 12229747 stack_push(value, sarg2);
18404 12229747 }
18405
18406 50 void do_loadi()
18407 {
18408 50 const int32_t stackoffset = get_register(sarg2) / 10000;
18409 50 const int32_t value = SH::read_stack(stackoffset);
18410 50 set_register(sarg1, value);
18411 50 }
18412
18413 8 void do_storei()
18414 {
18415 8 const int32_t stackoffset = get_register(sarg2) / 10000;
18416 8 const int32_t value = get_register(sarg1);
18417 8 SH::write_stack(stackoffset, value);
18418 8 }
18419
18420 void do_loadd()
18421 {
18422 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
18423 const int32_t value = SH::read_stack(stackoffset);
18424 set_register(sarg1, value);
18425 }
18426
18427 858818435 void do_load()
18428 {
18429 858818435 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18430 858818435 const int32_t value = SH::read_stack(stackoffset);
18431 858818435 set_register(sarg1, value);
18432 858818435 }
18433
18434 4 static void do_load_internal_array()
18435 {
18436
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 CHECK(ZScriptVersion::gc_arrays());
18437
18438 4 auto array = find_or_create_internal_script_array({sarg2, 0});
18439
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 set_register(sarg1, array ? array->id : 0);
18440 4 }
18441
18442 22 static void do_load_internal_array_ref()
18443 {
18444
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 CHECK(ZScriptVersion::gc_arrays());
18445
18446 22 int ref = get_register(sarg3);
18447 22 auto array = find_or_create_internal_script_array({sarg2, ref});
18448
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 set_register(sarg1, array ? array->id : 0);
18449 22 }
18450
18451 void do_stored(const bool v)
18452 {
18453 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
18454 const int32_t value = SH::get_arg(sarg1, v);
18455 SH::write_stack(stackoffset, value);
18456 }
18457
18458 141446081 void do_store(const bool v)
18459 {
18460 141446081 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18461 141446081 const int32_t value = SH::get_arg(sarg1, v);
18462 141446081 SH::write_stack(stackoffset, value);
18463 141446081 }
18464
18465 96399 void script_store_object(uint32_t offset, uint32_t new_id)
18466 {
18467 DCHECK(offset < MAX_STACK_SIZE);
18468
18469 // Increase, then decrease, to handle the case where a variable (holding the only reference to an object) is assigned to itself.
18470 // This is unlikely so lets not bother with a conditional that skips both ref modifications when the ids are equal.
18471 96399 uint32_t id = SH::read_stack(offset);
18472 96399 script_object_ref_inc(new_id);
18473
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 96063 times.
96399 if (ri->stack_pos_is_object.contains(offset))
18474 336 script_object_ref_dec(id);
18475 else
18476 96063 ri->stack_pos_is_object.insert(offset);
18477
18478 96399 SH::write_stack(offset, new_id);
18479
18480
2/2
✓ Branch 0 taken 41923 times.
✓ Branch 1 taken 54476 times.
96399 if (util::remove_if_exists(script_object_autorelease_pool, new_id))
18481 54476 script_object_ref_dec(new_id);
18482 96399 }
18483
18484 45159 void do_store_object(const bool v)
18485 {
18486 45159 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18487 45159 const int32_t new_id = SH::get_arg(sarg1, v);
18488 45159 script_store_object(stackoffset, new_id);
18489 45159 }
18490
18491 473193 void script_remove_object_ref(int32_t offset)
18492 {
18493
1/2
✓ Branch 0 taken 473193 times.
✗ Branch 1 not taken.
473193 if (offset < 0 || offset >= MAX_STACK_SIZE)
18494 {
18495 assert(false);
18496 return;
18497 }
18498
18499
2/2
✓ Branch 0 taken 347338 times.
✓ Branch 1 taken 125855 times.
473193 if (!ri->stack_pos_is_object.contains(offset))
18500 347338 return;
18501
18502 125855 uint32_t id = SH::read_stack(offset);
18503 125855 script_object_ref_dec(id);
18504 125855 ri->stack_pos_is_object.erase(offset);
18505 473193 }
18506
18507 void do_enqueue(const bool)
18508 {
18509 }
18510 void do_dequeue(const bool)
18511 {
18512 }
18513
18514 672422056 void do_comp(bool v, const bool inv = false)
18515 {
18516 672422056 bool v2 = false;
18517
1/2
✓ Branch 0 taken 672422056 times.
✗ Branch 1 not taken.
672422056 if(inv) zc_swap(v,v2);
18518 672422056 ri->cmp_op2 = SH::get_arg(sarg2, v);
18519 672422056 ri->cmp_op1 = SH::get_arg(sarg1, v2);
18520 672422056 ri->cmp_strcache = nullopt;
18521 672422056 }
18522
18523 void do_internal_strcmp()
18524 {
18525 int32_t arrayptr_a = get_register(sarg1);
18526 int32_t arrayptr_b = get_register(sarg2);
18527 string strA;
18528 string strB;
18529 ArrayH::getString(arrayptr_a, strA);
18530 ArrayH::getString(arrayptr_b, strB);
18531 ri->cmp_strcache = strcmp(strA.c_str(), strB.c_str());
18532 }
18533
18534 void do_internal_stricmp()
18535 {
18536 int32_t arrayptr_a = get_register(sarg1);
18537 int32_t arrayptr_b = get_register(sarg2);
18538 string strA;
18539 string strB;
18540 ArrayH::getString(arrayptr_a, strA);
18541 ArrayH::getString(arrayptr_b, strB);
18542 ri->cmp_strcache = stricmp(strA.c_str(), strB.c_str());
18543 }
18544
18545 5 void do_resize_array()
18546 {
18547 5 int32_t size = vbound(get_register(sarg2) / 10000, 0, 214748);
18548 5 dword ptrval = get_register(sarg1);
18549 5 ArrayManager am(ptrval);
18550 5 am.resize(size);
18551 5 }
18552
18553 void do_own_array(int arrindx, ScriptType scriptType, const int32_t UID)
18554 {
18555 ArrayManager am(arrindx);
18556
18557 if(am.internal())
18558 {
18559 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an internal array '%d'\n", arrindx);
18560 return;
18561 }
18562 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
18563 {
18564 //ignore global arrays
18565 }
18566 else if(!am.invalid())
18567 {
18568 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
18569 {
18570 arrayOwner[arrindx].reown(scriptType, UID);
18571 arrayOwner[arrindx].specOwned = true;
18572 }
18573 else if(arrindx < 0) //object array
18574 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an object-based array '%d'\n", arrindx);
18575 }
18576 else Z_scripterrlog_force_trace("Tried to 'OwnArray()' an invalid array '%d'\n", arrindx);
18577 }
18578
18579 void do_destroy_array()
18580 {
18581 if (ZScriptVersion::gc_arrays())
18582 {
18583 scripting_log_error_with_context("Cannot force destroy arrays in 3.0+");
18584 return;
18585 }
18586
18587 int arrindx = get_register(sarg1);
18588
18589 ArrayManager am(arrindx);
18590
18591 if(am.internal())
18592 {
18593 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an internal array '%d'\n", arrindx);
18594 return;
18595 }
18596
18597 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
18598 {
18599 //ignore global arrays
18600 }
18601 else if(!am.invalid())
18602 {
18603 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
18604 {
18605 arrayOwner[arrindx].clear();
18606
18607 if(localRAM[arrindx].Valid())
18608 localRAM[arrindx].Clear();
18609
18610 arrayOwner[arrindx].specCleared = true;
18611 }
18612 else if(arrindx < 0) //object array
18613 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an object-based array '%d'\n", arrindx);
18614 }
18615 else Z_scripterrlog_force_trace("Tried to 'DestroyArray()' an invalid array '%d'\n", arrindx);
18616 }
18617
18618 13691297 static dword allocatemem_old(int32_t size, bool local, ScriptType type, const uint32_t UID, script_object_type object_type)
18619 {
18620 dword ptrval;
18621
18622
1/2
✓ Branch 0 taken 13691297 times.
✗ Branch 1 not taken.
13691297 if(size < 0)
18623 {
18624 Z_scripterrlog_force_trace("Array initialized to invalid size of %d\n", size);
18625 return 0;
18626 }
18627
18628
2/2
✓ Branch 0 taken 13690535 times.
✓ Branch 1 taken 762 times.
13691297 if(local)
18629 {
18630 //localRAM[0] is used as an invalid container, so 0 can be the NULL pointer in ZScript
18631
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 446248809 times.
✓ Branch 2 taken 432558274 times.
✓ Branch 3 taken 13690535 times.
446248809 for(ptrval = 1; ptrval < NUM_ZSCRIPT_ARRAYS && localRAM[ptrval].Valid(); ptrval++) ;
18632
18633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690535 times.
13690535 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
18634 {
18635 Z_scripterrlog_force_trace("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
18636 ptrval = 0;
18637 DCHECK(false);
18638 }
18639 else
18640 {
18641 13690535 ZScriptArray &a = localRAM[ptrval];
18642
18643 13690535 a.Resize(size);
18644 13690535 a.setValid(true);
18645 13690535 a.setObjectType(object_type);
18646
18647
2/2
✓ Branch 0 taken 211531489 times.
✓ Branch 1 taken 13690535 times.
225222024 for(dword j = 0; j < (dword)size; j++)
18648 211531489 a[j] = 0; //initialize array
18649
18650 // Keep track of which object created the array so we know which to deallocate
18651 13690535 arrayOwner[ptrval].clear();
18652 13690535 arrayOwner[ptrval].reown(type, UID);
18653 }
18654 13690535 }
18655 else
18656 {
18657 //Globals are only allocated here at first play, otherwise in init_game
18658
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23485 times.
✓ Branch 2 taken 22723 times.
✓ Branch 3 taken 762 times.
23485 for(ptrval = 0; ptrval < game->globalRAM.size() && game->globalRAM[ptrval].Valid(); ptrval++) ;
18659
18660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 762 times.
762 if(ptrval >= game->globalRAM.size())
18661 {
18662 Z_scripterrlog_force_trace("Invalid pointer value of %u passed to global allocate\n", ptrval);
18663 ptrval = 0;
18664 //this shouldn't happen, unless people are putting ALLOCATEGMEM in their ZASM scripts where they shouldn't be
18665 DCHECK(false);
18666 return ptrval * 10000;
18667 }
18668
18669 762 ZScriptArray &a = game->globalRAM[ptrval];
18670
18671 762 a.Resize(size);
18672 762 a.setValid(true);
18673 762 a.setObjectType(object_type);
18674
18675
2/2
✓ Branch 0 taken 879965 times.
✓ Branch 1 taken 762 times.
880727 for(dword j = 0; j < (dword)size; j++)
18676 879965 a[j] = 0;
18677
18678 762 ptrval += NUM_ZSCRIPT_ARRAYS; //so each pointer has a unique value
18679 }
18680
18681 13691297 return ptrval * 10000;
18682 13691297 }
18683
18684 13770503 uint32_t allocatemem(int32_t size, bool local, ScriptType type, const uint32_t UID, script_object_type object_type)
18685 {
18686
2/2
✓ Branch 0 taken 13691297 times.
✓ Branch 1 taken 79206 times.
13770503 if (!ZScriptVersion::gc_arrays())
18687 13691297 return allocatemem_old(size, local, type, UID, object_type);
18688
18689
1/2
✓ Branch 0 taken 79206 times.
✗ Branch 1 not taken.
79206 if(size < 0)
18690 {
18691 Z_scripterrlog_force_trace("Array initialized to invalid size of %d\n", size);
18692 return 0;
18693 }
18694
18695 79206 auto* array = script_arrays.create();
18696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79206 times.
79206 if (!array)
18697 return 0;
18698
18699 79206 ZScriptArray &a = array->arr;
18700 79206 a.Resize(size);
18701 79206 a.setValid(true);
18702 79206 a.setObjectType(object_type);
18703
18704
2/2
✓ Branch 0 taken 1122867 times.
✓ Branch 1 taken 79206 times.
1202073 for(dword j = 0; j < (dword)size; j++)
18705 1122867 a[j] = 0; //initialize array
18706
18707 79206 return array->id;
18708 13770503 }
18709
18710 13770503 void do_allocatemem(bool v, const bool local, ScriptType type, const uint32_t UID)
18711 {
18712 13770503 int32_t size = SH::get_arg(sarg2, v) / 10000;
18713
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13770503 times.
✓ Branch 2 taken 13770503 times.
✗ Branch 3 not taken.
13770503 assert(sarg3 >= 0 && sarg3 <= (int)script_object_type::last);
18714 13770503 uint32_t id = allocatemem(size, local, type, UID, (script_object_type)sarg3);
18715 13770503 set_register(sarg1, id);
18716 13770503 }
18717
18718 13656663 void do_deallocatemem()
18719 {
18720 13656663 const int32_t ptrval = get_register(sarg1) / 10000;
18721
18722 13656663 FFScript::deallocateArray(ptrval);
18723 13656663 }
18724
18725 ///----------------------------------------------------------------------------------------------------//
18726 //Mathematical
18727
18728 224442504 void do_add(const bool v)
18729 {
18730 224442504 int32_t temp = SH::get_arg(sarg2, v);
18731 224442504 int32_t temp2 = get_register(sarg1);
18732
18733 224442504 set_register(sarg1, temp2 + temp);
18734 224442504 }
18735
18736 45189722 void do_sub(bool v, const bool inv = false)
18737 {
18738 45189722 bool v2 = false;
18739
2/2
✓ Branch 0 taken 45171381 times.
✓ Branch 1 taken 18341 times.
45189722 if(inv) zc_swap(v,v2);
18740
2/2
✓ Branch 0 taken 18341 times.
✓ Branch 1 taken 45171381 times.
45189722 auto destreg = (inv ? sarg2 : sarg1);
18741 45189722 int32_t temp = SH::get_arg(sarg2, v);
18742 45189722 int32_t temp2 = SH::get_arg(sarg1, v2);
18743 45189722 set_register(destreg, temp2 - temp);
18744 45189722 }
18745
18746 28485000 void do_mult(const bool v)
18747 {
18748 28485000 int64_t temp = SH::get_arg(sarg2, v);
18749 28485000 int32_t temp2 = get_register(sarg1);
18750
18751 28485000 set_register(sarg1, int32_t((temp * temp2) / 10000));
18752 28485000 }
18753
18754 5154673 void do_div(bool v, const bool inv = false)
18755 {
18756 5154673 bool v2 = false;
18757
1/2
✓ Branch 0 taken 5154673 times.
✗ Branch 1 not taken.
5154673 if(inv) zc_swap(v,v2);
18758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5154673 times.
5154673 auto destreg = (inv ? sarg2 : sarg1);
18759 5154673 int64_t temp = SH::get_arg(sarg2, v);
18760 5154673 int64_t temp2 = SH::get_arg(sarg1, v2);
18761
18762
2/2
✓ Branch 0 taken 5154637 times.
✓ Branch 1 taken 36 times.
5154673 if(temp == 0)
18763 {
18764
2/4
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
36 scripting_log_error_with_context("Attempted to divide by zero!");
18765 36 set_register(destreg, int32_t(sign(temp2) * MAX_SIGNED_32));
18766 36 }
18767 else
18768 {
18769 5154637 set_register(destreg, int32_t((temp2 * 10000) / temp));
18770 }
18771 5154673 }
18772
18773 5327027 void do_mod(bool v, const bool inv = false)
18774 {
18775 5327027 bool v2 = false;
18776
1/2
✓ Branch 0 taken 5327027 times.
✗ Branch 1 not taken.
5327027 if(inv) zc_swap(v,v2);
18777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5327027 times.
5327027 auto destreg = (inv ? sarg2 : sarg1);
18778 5327027 int32_t temp = SH::get_arg(sarg2, v);
18779 5327027 int32_t temp2 = SH::get_arg(sarg1, v2);
18780
18781
2/2
✓ Branch 0 taken 5327015 times.
✓ Branch 1 taken 12 times.
5327027 if(temp == 0)
18782 {
18783
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 scripting_log_error_with_context("Attempted to modulo by zero!");
18784 12 temp = 1;
18785 12 }
18786
18787 5327027 set_register(destreg, temp2 % temp);
18788 5327027 }
18789
18790 16033659 void do_trig(const bool v, const byte type)
18791 {
18792 16033659 double rangle = (SH::get_arg(sarg2, v) / 10000.0) * PI / 180.0;
18793
18794
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9550421 times.
✓ Branch 2 taken 6483138 times.
✓ Branch 3 taken 100 times.
16033659 switch(type)
18795 {
18796 case 0:
18797 9550421 set_register(sarg1, int32_t(zc::math::Sin(rangle) * 10000.0));
18798 9550421 break;
18799
18800 case 1:
18801 6483138 set_register(sarg1, int32_t(zc::math::Cos(rangle) * 10000.0));
18802 6483138 break;
18803
18804 case 2:
18805 100 set_register(sarg1, int32_t(zc::math::Tan(rangle) * 10000.0));
18806 100 break;
18807 }
18808 16033659 }
18809
18810 1480 void do_degtorad()
18811 {
18812 1480 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (PI / 180.0);
18813 1480 rangle += rangle < 0?-0.00005:0.00005;
18814
18815 1480 set_register(sarg1, int32_t(rangle * 10000.0));
18816 1480 }
18817
18818 138537 void do_radtodeg()
18819 {
18820 138537 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (180.0 / PI);
18821
18822 138537 set_register(sarg1, int32_t(rangle * 10000.0));
18823 138537 }
18824
18825 14918 void do_asin(const bool v)
18826 {
18827 14918 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18828
18829
2/4
✓ Branch 0 taken 14918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14918 times.
✗ Branch 3 not taken.
14918 if(temp >= -1 && temp <= 1)
18830 14918 set_register(sarg1, int32_t(asin(temp) * 10000.0));
18831 else
18832 {
18833 Z_scripterrlog("Script attempted to pass %f into ArcSin!\n",temp);
18834 set_register(sarg1, -10000);
18835 }
18836 14918 }
18837
18838 void do_acos(const bool v)
18839 {
18840 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18841
18842 if(temp >= -1 && temp <= 1)
18843 set_register(sarg1, int32_t(acos(temp) * 10000.0));
18844 else
18845 {
18846 Z_scripterrlog("Script attempted to pass %f into ArcCos!\n",temp);
18847 set_register(sarg1, -10000);
18848 }
18849 }
18850
18851 5879938 void do_arctan()
18852 {
18853 5879938 double xpos = ri->d[rINDEX] / 10000.0;
18854 5879938 double ypos = ri->d[rINDEX2] / 10000.0;
18855
18856 5879938 set_register(sarg1, int32_t(atan2(ypos, xpos) * 10000.0));
18857 5879938 }
18858
18859 2394272 void do_abs(const bool v)
18860 {
18861 2394272 int32_t temp = SH::get_arg(sarg1, v);
18862 2394272 set_register(sarg1, abs(temp));
18863 2394272 }
18864
18865 969 void do_log10(const bool v)
18866 {
18867 969 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
18868
18869
1/2
✓ Branch 0 taken 969 times.
✗ Branch 1 not taken.
969 if(temp > 0)
18870 969 set_register(sarg1, int32_t(log10(temp) * 10000.0));
18871 else
18872 {
18873 Z_scripterrlog("Script tried to calculate log of %f\n", temp / 10000.0);
18874 set_register(sarg1, 0);
18875 }
18876 969 }
18877
18878 648 void do_naturallog(const bool v)
18879 {
18880 648 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
18881
18882
1/2
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
648 if(temp > 0)
18883 648 set_register(sarg1, int32_t(log(temp) * 10000.0));
18884 else
18885 {
18886 Z_scripterrlog("Script tried to calculate ln of %f\n", temp / 10000.0);
18887 set_register(sarg1, 0);
18888 }
18889 648 }
18890
18891 176378 void do_min(const bool v)
18892 {
18893 176378 int32_t temp = SH::get_arg(sarg2, v);
18894 176378 int32_t temp2 = get_register(sarg1);
18895
2/2
✓ Branch 0 taken 84107 times.
✓ Branch 1 taken 92271 times.
176378 set_register(sarg1, zc_min(temp2, temp));
18896 176378 }
18897
18898 53727 void do_max(const bool v)
18899 {
18900 53727 int32_t temp = SH::get_arg(sarg2, v);
18901 53727 int32_t temp2 = get_register(sarg1);
18902
18903
2/2
✓ Branch 0 taken 11701 times.
✓ Branch 1 taken 42026 times.
53727 set_register(sarg1, zc_max(temp2, temp));
18904 53727 }
18905 void do_wrap_rad(const bool v)
18906 {
18907 ri->d[rEXP1] = wrap_zslong_rad(SH::get_arg(sarg1, v));
18908 }
18909 2397 void do_wrap_deg(const bool v)
18910 {
18911 2397 ri->d[rEXP1] = wrap_zslong_deg(SH::get_arg(sarg1, v));
18912 2397 }
18913
18914
18915 2912197 void do_rnd(const bool v)
18916 {
18917 2912197 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18918
18919
2/2
✓ Branch 0 taken 2886432 times.
✓ Branch 1 taken 25765 times.
2912197 if(temp > 0)
18920 2886432 set_register(sarg1, (zc_oldrand() % temp) * 10000);
18921
2/2
✓ Branch 0 taken 2755 times.
✓ Branch 1 taken 23010 times.
25765 else if(temp < 0)
18922 2755 set_register(sarg1, (zc_oldrand() % (-temp)) * -10000);
18923 else
18924 23010 set_register(sarg1, 0); // Just return 0. (Do not log an error)
18925 2912197 }
18926
18927 void do_srnd(const bool v)
18928 {
18929 uint32_t seed = SH::get_arg(sarg1, v); //Do not `/10000`- allow the decimal portion to be used! -V
18930 zc_game_srand(seed);
18931 }
18932
18933 void do_srndrnd()
18934 {
18935 //Randomize the seed to the current system time, + or - the product of 2 random numbers.
18936 int32_t seed = time(0) + ((zc_rand() * int64_t(zc_rand())) * (zc_rand(1) ? 1 : -1));
18937 set_register(sarg1, seed);
18938 zc_game_srand(seed);
18939 }
18940
18941 //Returns the system Real-Time-Clock value for a specific type.
18942 15 void FFScript::getRTC(const bool v)
18943 {
18944 //int32_t type = get_register(sarg1) / 10000;
18945 //int32_t time = getTime(type);
18946 15 set_register(sarg1, getTime((get_register(sarg1) / 10000)) * 10000);
18947 15 }
18948
18949
18950 void do_factorial(const bool v)
18951 {
18952 int32_t temp;
18953
18954 if(v)
18955 return; //must factorial a register, not a value (why is this exactly? ~Joe123)
18956 else
18957 {
18958 temp = get_register(sarg1) / 10000;
18959
18960 if(temp < 2)
18961 {
18962 set_register(sarg1, temp >= 0 ? 10000 : 0);
18963 return;
18964 }
18965 }
18966
18967 int32_t temp2 = 1;
18968
18969 for(int32_t temp3 = temp; temp > 1; temp--)
18970 temp2 *= temp3;
18971
18972 set_register(sarg1, temp2 * 10000);
18973 }
18974
18975 6556 void do_power(bool v, const bool inv = false)
18976 {
18977 6556 bool v2 = false;
18978
1/2
✓ Branch 0 taken 6556 times.
✗ Branch 1 not taken.
6556 if(inv) zc_swap(v,v2);
18979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6556 times.
6556 auto destreg = (inv ? sarg2 : sarg1);
18980 6556 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18981 6556 double temp2 = double(SH::get_arg(sarg1, v2)) / 10000.0;
18982
18983
3/4
✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 5263 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1293 times.
6556 if(temp == 0 && temp2 == 0)
18984 {
18985 set_register(destreg, 10000);
18986 return;
18987 }
18988
18989 6556 set_register(destreg, int32_t(pow(temp2, temp) * 10000.0));
18990 6556 }
18991
18992 void do_lpower(bool v, const bool inv = false)
18993 {
18994 bool v2 = false;
18995 if(inv) zc_swap(v,v2);
18996 auto destreg = (inv ? sarg2 : sarg1);
18997 int32_t temp = SH::get_arg(sarg2, v);
18998 int32_t temp2 = SH::get_arg(sarg1, v2);
18999
19000 if(temp == 0 && temp2 == 0)
19001 {
19002 set_register(destreg, 1);
19003 return;
19004 }
19005
19006 set_register(destreg, int32_t(pow(temp2, temp)));
19007 }
19008
19009 //could use recursion or something to avoid truncation.
19010 void do_ipower(const bool v)
19011 {
19012 double sarg2val = double(SH::get_arg(sarg2, v));
19013 if ( sarg2val == 0 )
19014 {
19015 Z_scripterrlog("Division by 0 Err: InvPower() exponent divisor cannot be 0!!\n");
19016 set_register(sarg1, 1);
19017 return;
19018 }
19019 double temp = 10000.0 / sarg2val;
19020 double temp2 = double(get_register(sarg1)) / 10000.0;
19021
19022 if(temp == 0 && temp2 == 0)
19023 {
19024 set_register(sarg1, 1);
19025 return;
19026 }
19027
19028 set_register(sarg1, int32_t(pow(temp2, temp) * 10000.0));
19029 }
19030
19031 10089782 void do_sqroot(const bool v)
19032 {
19033 10089782 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
19034
19035
2/2
✓ Branch 0 taken 422 times.
✓ Branch 1 taken 10089360 times.
10089782 if(temp < 0)
19036 {
19037 422 Z_scripterrlog("Script attempted to calculate square root of %f!\n", temp);
19038 422 set_register(sarg1, -10000);
19039 422 return;
19040 }
19041
19042 10089360 set_register(sarg1, int32_t(sqrt(temp) * 10000.0));
19043 10089782 }
19044
19045 ///----------------------------------------------------------------------------------------------------//
19046 //Bitwise
19047
19048 41700058 void do_and(const bool v)
19049 {
19050 41700058 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19051 41700058 int32_t temp2 = get_register(sarg1) / 10000;
19052 41700058 set_register(sarg1, (temp2 & temp) * 10000);
19053 41700058 }
19054
19055 45050 void do_and32(const bool v)
19056 {
19057 45050 int32_t temp = SH::get_arg(sarg2, v);
19058 45050 int32_t temp2 = get_register(sarg1);
19059 45050 set_register(sarg1, (temp2 & temp));
19060 45050 }
19061
19062 9406051 void do_or(const bool v)
19063 {
19064 9406051 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19065 9406051 int32_t temp2 = get_register(sarg1) / 10000;
19066 9406051 set_register(sarg1, (temp2 | temp) * 10000);
19067 9406051 }
19068
19069 17 void do_or32(const bool v)
19070 {
19071 17 int32_t temp = SH::get_arg(sarg2, v);
19072 17 int32_t temp2 = get_register(sarg1);
19073 17 set_register(sarg1, (temp2 | temp));
19074 17 }
19075
19076 921308 void do_xor(const bool v)
19077 {
19078 921308 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19079 921308 int32_t temp2 = get_register(sarg1) / 10000;
19080 921308 set_register(sarg1, (temp2 ^ temp) * 10000);
19081 921308 }
19082
19083 void do_xor32(const bool v)
19084 {
19085 int32_t temp = SH::get_arg(sarg2, v);
19086 int32_t temp2 = get_register(sarg1);
19087 set_register(sarg1, (temp2 ^ temp));
19088 }
19089
19090 void do_nand(const bool v)
19091 {
19092 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19093 int32_t temp2 = get_register(sarg1) / 10000;
19094 set_register(sarg1, (~(temp2 & temp)) * 10000);
19095 }
19096
19097 void do_nor(const bool v)
19098 {
19099 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19100 int32_t temp2 = get_register(sarg1) / 10000;
19101 set_register(sarg1, (~(temp2 | temp)) * 10000);
19102 }
19103
19104 void do_xnor(const bool v)
19105 {
19106 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19107 int32_t temp2 = get_register(sarg1) / 10000;
19108 set_register(sarg1, (~(temp2 ^ temp)) * 10000);
19109 }
19110
19111 void do_not(const bool v)
19112 {
19113 int32_t temp = SH::get_arg(sarg2, v);
19114 set_register(sarg1, !temp);
19115 }
19116
19117 3709786 void do_bitwisenot(const bool v)
19118 {
19119 3709786 int32_t temp = SH::get_arg(sarg1, v) / 10000;
19120 3709786 set_register(sarg1, (~temp) * 10000);
19121 3709786 }
19122
19123 void do_bitwisenot32(const bool v)
19124 {
19125 int32_t temp = SH::get_arg(sarg1, v);
19126 set_register(sarg1, (~temp));
19127 }
19128
19129 76717177 void do_lshift(const bool v)
19130 {
19131 76717177 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19132 76717177 int32_t temp2 = get_register(sarg1) / 10000;
19133 76717177 set_register(sarg1, (temp2 << temp) * 10000);
19134 76717177 }
19135
19136 22 void do_lshift32(const bool v)
19137 {
19138 22 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19139 22 int32_t temp2 = get_register(sarg1);
19140 22 set_register(sarg1, (temp2 << temp));
19141 22 }
19142
19143 31394534 void do_rshift(const bool v)
19144 {
19145 31394534 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19146 31394534 int32_t temp2 = get_register(sarg1) / 10000;
19147 31394534 set_register(sarg1, (temp2 >> temp) * 10000);
19148 31394534 }
19149
19150 34296 void do_rshift32(const bool v)
19151 {
19152 34296 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19153 34296 int32_t temp2 = get_register(sarg1);
19154 34296 set_register(sarg1, (temp2 >> temp));
19155 34296 }
19156
19157 ///----------------------------------------------------------------------------------------------------//
19158 //Casting
19159
19160 5131758 void do_boolcast(const bool isFloat)
19161 {
19162
2/2
✓ Branch 0 taken 1720009 times.
✓ Branch 1 taken 3411749 times.
5131758 set_register(sarg1, (get_register(sarg1) ? (isFloat ? 1 : 10000) : 0));
19163 5131758 }
19164
19165 ///----------------------------------------------------------------------------------------------------//
19166 //Text ptr functions
19167 6352 void do_fontheight()
19168 {
19169 6352 int32_t font = get_register(sarg1)/10000;
19170 6352 ri->d[rEXP1] = text_height(get_zc_font(font))*10000;
19171 6352 }
19172
19173 17821 void do_strwidth()
19174 {
19175 17821 int32_t strptr = get_register(sarg1);
19176 17821 int32_t font = get_register(sarg2)/10000;
19177 17821 string the_string;
19178
1/2
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
17821 ArrayH::getString(strptr, the_string, 512);
19179
2/4
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17821 times.
✗ Branch 3 not taken.
17821 ri->d[rEXP1] = text_length(get_zc_font(font), the_string.c_str())*10000;
19180 17821 }
19181
19182 37547 void do_charwidth()
19183 {
19184 37547 char chr = get_register(sarg1)/10000;
19185 37547 int32_t font = get_register(sarg2)/10000;
19186 37547 char *cstr = new char[2];
19187 37547 cstr[0] = chr;
19188 37547 cstr[1] = '\0';
19189 37547 ri->d[rEXP1] = text_length(get_zc_font(font), cstr)*10000;
19190
1/2
✓ Branch 0 taken 37547 times.
✗ Branch 1 not taken.
37547 delete[] cstr;
19191 37547 }
19192
19193 int32_t do_msgwidth(int32_t ID)
19194 {
19195 if(BC::checkMessage(ID) != SH::_NoError)
19196 {
19197 return -1;
19198 }
19199
19200 int32_t v = text_length(get_zc_font(MsgStrings[ID].font),
19201 MsgStrings[ID].s.substr(0,MsgStrings[ID].s.find_last_not_of(' ')+1).c_str());
19202 return v;
19203 }
19204
19205 int32_t do_msgheight(int32_t ID)
19206 {
19207 if(BC::checkMessage(ID) != SH::_NoError)
19208 {
19209 return -1;
19210 }
19211 return text_height(get_zc_font(MsgStrings[ID].font));
19212 }
19213
19214 ///----------------------------------------------------------------------------------------------------//
19215 //Gameplay functions
19216
19217 107 void do_warp(bool v)
19218 {
19219 107 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
19220 107 int32_t screen = SH::get_arg(sarg2, v) / 10000;
19221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)dmapid) >= MAXDMAPS )
19222 {
19223 Z_scripterrlog("Invalid DMap ID (%d) passed to Warp(). Aborting.\n", dmapid);
19224 return;
19225 }
19226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)screen) >= MAPSCRS )
19227 {
19228 Z_scripterrlog("Invalid Screen Index (%d) passed to Warp(). Aborting.\n", screen);
19229 return;
19230 }
19231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
19232 {
19233 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
19234 return;
19235 }
19236 107 hero_scr->sidewarpdmap[0] = dmapid;
19237 107 hero_scr->sidewarpscr[0] = screen;
19238 107 hero_scr->sidewarptype[0] = wtIWARP;
19239
1/2
✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
107 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
19240 {
19241 hero_scr->warpreturnc &= ~(3 << 8);
19242 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
19243 }
19244 107 Hero.ffwarp = true;
19245 107 }
19246
19247 127 void do_pitwarp(bool v)
19248 {
19249 127 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
19250 127 int32_t screen = SH::get_arg(sarg2, v) / 10000;
19251
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)dmapid) >= MAXDMAPS )
19252 {
19253 Z_scripterrlog("Invalid DMap ID (%d) passed to PitWarp(). Aborting.\n", dmapid);
19254 return;
19255 }
19256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)screen) >= MAPSCRS )
19257 {
19258 Z_scripterrlog("Invalid Screen Index (%d) passed to PitWarp(). Aborting.\n", screen);
19259 return;
19260 }
19261 //Extra sanity guard.
19262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
19263 {
19264 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
19265 return;
19266 }
19267 127 hero_scr->sidewarpdmap[0] = dmapid;
19268 127 hero_scr->sidewarpscr[0] = screen;
19269 127 hero_scr->sidewarptype[0] = wtIWARP;
19270
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
19271 {
19272 hero_scr->warpreturnc &= ~(3 << 8);
19273 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
19274 }
19275 127 Hero.ffwarp = true;
19276 127 Hero.ffpit = true;
19277 127 }
19278
19279
19280
19281 void do_showsavescreen()
19282 {
19283 bool didsaved = save_game(false, 0);
19284 set_register(sarg1, didsaved ? 10000 : 0);
19285 }
19286
19287 11096 void do_selectweapon(bool v, int32_t btn)
19288 {
19289
2/4
✓ Branch 0 taken 5436 times.
✓ Branch 1 taken 5660 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11096 switch(btn)
19290 {
19291 case 1:
19292
1/2
✓ Branch 0 taken 5660 times.
✗ Branch 1 not taken.
5660 if(!get_qr(qr_SELECTAWPN))
19293 return;
19294 5660 break;
19295 case 2:
19296 if(!get_qr(qr_SET_XBUTTON_ITEMS))
19297 return;
19298 break;
19299 case 3:
19300 if(!get_qr(qr_SET_YBUTTON_ITEMS))
19301 return;
19302 break;
19303 }
19304
19305 11096 byte dir=(byte)(SH::get_arg(sarg1, v)/10000);
19306
19307 // Selection directions don't match the normal ones...
19308
2/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 11016 times.
11096 switch(dir)
19309 {
19310 case 0:
19311 dir=SEL_UP;
19312 break;
19313
19314 case 1:
19315 dir=SEL_DOWN;
19316 break;
19317
19318 case 2:
19319 80 dir=SEL_LEFT;
19320 80 break;
19321
19322 case 3:
19323 11016 dir=SEL_RIGHT;
19324 11016 break;
19325
19326 default:
19327 return;
19328 }
19329
19330
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5436 times.
✓ Branch 2 taken 5660 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
11096 switch(btn)
19331 {
19332 case 0:
19333 5436 selectNextBWpn(dir);
19334 5436 break;
19335 case 1:
19336 5660 selectNextAWpn(dir);
19337 5660 break;
19338 case 2:
19339 selectNextXWpn(dir);
19340 break;
19341 case 3:
19342 selectNextYWpn(dir);
19343 break;
19344 }
19345 11096 }
19346
19347 ///----------------------------------------------------------------------------------------------------//
19348 //Screen Information
19349
19350 21032557 void do_issolid()
19351 {
19352 21032557 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19353 21032557 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19354
19355 21032557 set_register(sarg1, (_walkflag(x, y, 1) ? 10000 : 0));
19356 21032557 }
19357
19358 void do_mapdataissolid()
19359 {
19360 auto result = decode_mapdata_ref(ri->mapsref);
19361 if (!result.scr)
19362 {
19363 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
19364 set_register(sarg1,10000);
19365 }
19366 else
19367 {
19368 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19369 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19370
19371 if (result.type == mapdata_type::CanonicalScreen)
19372 {
19373 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
19374 return;
19375 }
19376
19377 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
19378 {
19379 set_register(sarg1, (_walkflag(x, y, 1)) ? 10000 : 0);
19380 }
19381 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
19382 {
19383 mapscr* s0 = GetScrollingMapscr(0, x, y);
19384 mapscr* s1 = GetScrollingMapscr(1, x, y);
19385 mapscr* s2 = GetScrollingMapscr(2, x, y);
19386 if (!s1->valid) s1 = s0;
19387 if (!s2->valid) s2 = s0;
19388 bool result = _walkflag_new(s0, s1, s2, x, y, 0_zf, true);
19389 set_register(sarg1, result ? 10000 : 0);
19390 }
19391 else
19392 {
19393 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
19394 }
19395 }
19396 }
19397
19398 void do_mapdataissolid_layer()
19399 {
19400 auto result = decode_mapdata_ref(ri->mapsref);
19401 if (!result.scr)
19402 {
19403 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
19404 set_register(sarg1,10000);
19405 }
19406 else
19407 {
19408 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19409 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19410 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
19411 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
19412 {
19413 set_register(sarg1,10000);
19414 }
19415 else
19416 {
19417 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
19418 {
19419 set_register(sarg1, (_walkflag_layer(x, y, 1, result.scr)) ? 10000 : 0);
19420 }
19421 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
19422 {
19423 set_register(sarg1, (_walkflag_layer_scrolling(x, y, 1, result.scr)) ? 10000 : 0);
19424 }
19425 else
19426 {
19427 mapscr* m = result.scr;
19428
19429 if(layer > 0)
19430 {
19431 if(m->layermap[layer] == 0)
19432 {
19433 set_register(sarg1,10000);
19434 return;
19435 }
19436
19437 m = &TheMaps[(m->layermap[layer]*MAPSCRS + m->layerscreen[layer])];
19438 }
19439
19440 set_register(sarg1, (_walkflag_layer(x, y, 1, m) ? 10000 : 0));
19441 }
19442 }
19443 }
19444 }
19445
19446 void do_issolid_layer()
19447 {
19448 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19449 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19450 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
19451 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
19452 {
19453 set_register(sarg1,10000);
19454 }
19455 else
19456 {
19457 set_register(sarg1, (_walkflag_layer(x, y, layer - 1, 1)) ? 10000 : 0);
19458 }
19459 }
19460
19461 257 void do_setsidewarp()
19462 {
19463 257 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
19464 257 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
19465 257 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
19466 257 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
19467
19468 257 current_zasm_extra_context = "warp";
19469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
19470 return;
19471
19472 257 current_zasm_extra_context = "screen";
19473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
19474 return;
19475
19476 257 current_zasm_extra_context = "dmap";
19477
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
19478 return;
19479
19480 257 current_zasm_extra_context = "type";
19481
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
19482 return;
19483
19484 257 current_zasm_extra_context = "";
19485
19486 257 mapscr* scr = get_scr(ri->screenref);
19487
19488
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(scrn > -1)
19489 257 scr->sidewarpscr[warp] = scrn;
19490
19491
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(dmap > -1)
19492 257 scr->sidewarpdmap[warp] = dmap;
19493
19494
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(type > -1)
19495 257 scr->sidewarptype[warp] = type;
19496 257 }
19497
19498 5 void do_settilewarp()
19499 {
19500 5 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
19501 5 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
19502 5 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
19503 5 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
19504
19505 5 current_zasm_extra_context = "warp";
19506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
19507 return;
19508
19509 5 current_zasm_extra_context = "screen";
19510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
19511 return;
19512
19513 5 current_zasm_extra_context = "dmap";
19514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
19515 return;
19516
19517 5 current_zasm_extra_context = "type";
19518
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
19519 return;
19520
19521 5 current_zasm_extra_context = "";
19522
19523 5 mapscr* scr = get_scr(ri->screenref);
19524
19525
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scrn > -1)
19526 5 scr->tilewarpscr[warp] = scrn;
19527
19528
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(dmap > -1)
19529 5 scr->tilewarpdmap[warp] = dmap;
19530
19531
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(type > -1)
19532 5 scr->tilewarptype[warp] = type;
19533 5 }
19534
19535 354943 void do_getsidewarpdmap(const bool v)
19536 {
19537 354943 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19538
19539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354943 times.
354943 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19540 {
19541 set_register(sarg1, -10000);
19542 return;
19543 }
19544
19545 354943 set_register(sarg1, get_scr(ri->screenref)->sidewarpdmap[warp]*10000);
19546 354943 }
19547
19548 3 void do_getsidewarpscr(const bool v)
19549 {
19550 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19551
19552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19553 {
19554 set_register(sarg1, -10000);
19555 return;
19556 }
19557
19558 3 set_register(sarg1, get_scr(ri->screenref)->sidewarpscr[warp]*10000);
19559 3 }
19560
19561 void do_getsidewarptype(const bool v)
19562 {
19563 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19564
19565 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19566 {
19567 set_register(sarg1, -10000);
19568 return;
19569 }
19570
19571 set_register(sarg1, get_scr(ri->screenref)->sidewarptype[warp]*10000);
19572 }
19573
19574 354990 void do_gettilewarpdmap(const bool v)
19575 {
19576 354990 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19577
19578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354990 times.
354990 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19579 {
19580 set_register(sarg1, -10000);
19581 return;
19582 }
19583
19584 354990 set_register(sarg1, get_scr(ri->screenref)->tilewarpdmap[warp]*10000);
19585 354990 }
19586
19587 50 void do_gettilewarpscr(const bool v)
19588 {
19589 50 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19590
19591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19592 {
19593 set_register(sarg1, -10000);
19594 return;
19595 }
19596
19597 50 set_register(sarg1, get_scr(ri->screenref)->tilewarpscr[warp]*10000);
19598 50 }
19599
19600 3 void do_gettilewarptype(const bool v)
19601 {
19602 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19603
19604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19605 {
19606 set_register(sarg1, -10000);
19607 return;
19608 }
19609
19610 3 set_register(sarg1, get_scr(ri->screenref)->tilewarptype[warp]*10000);
19611 3 }
19612
19613 13670631 void do_layerscreen()
19614 {
19615 13670631 int32_t layer = (get_register(sarg2) / 10000) - 1;
19616
19617
3/4
✓ Branch 0 taken 13670631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11796293 times.
✓ Branch 3 taken 1874338 times.
13670631 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
19618 1874338 set_register(sarg1, -10000);
19619 else
19620 11796293 set_register(sarg1, get_scr(ri->screenref)->layerscreen[layer] * 10000);
19621 13670631 }
19622
19623 18282859 void do_layermap()
19624 {
19625 18282859 int32_t layer = (get_register(sarg2) / 10000) - 1;
19626
19627
3/4
✓ Branch 0 taken 18282859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15796322 times.
✓ Branch 3 taken 2486537 times.
18282859 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
19628 2486537 set_register(sarg1, -10000);
19629 else
19630 15796322 set_register(sarg1, get_scr(ri->screenref)->layermap[layer] * 10000);
19631 18282859 }
19632
19633
19634
19635 475 void do_triggersecrets(int screen)
19636 {
19637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 475 times.
475 if (!is_in_current_region(screen))
19638 {
19639 scripting_log_error_with_context("Must be given a screen in the current region. got: {}", screen);
19640 return;
19641 }
19642
19643 475 trigger_secrets_for_screen(TriggerSource::Script, screen, false);
19644 475 }
19645
19646 void FFScript::do_graphics_getpixel()
19647 {
19648 int32_t yoffset = 0;
19649 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
19650 int32_t ref = (ri->d[rEXP1]);
19651
19652 BITMAP *bitty = FFCore.GetScriptBitmap(ref, screen);
19653 int32_t xpos = ri->d[rINDEX2] / 10000;
19654
19655 if(!brokenOffset && (ref-10) == -1 )
19656 {
19657 yoffset = 56; //should this be -56?
19658 }
19659 else
19660 {
19661 yoffset = 0;
19662 }
19663
19664 int32_t ypos = (ri->d[rINDEX] / 10000)+yoffset;
19665 if(!bitty)
19666 {
19667 bitty = scrollbuf;
19668 }
19669
19670 int32_t ret = getpixel(bitty, xpos, ypos); //This is a palette index value.
19671
19672 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
19673 ret *= 10000;
19674 set_register(sarg1, ret);
19675 }
19676
19677
19678
19679
19680 ///----------------------------------------------------------------------------------------------------//
19681 //Pointer handling
19682
19683 587 bool is_valid_array(int32_t ptr)
19684 {
19685
2/2
✓ Branch 0 taken 572 times.
✓ Branch 1 taken 15 times.
587 if(!ptr) return false;
19686
19687
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 566 times.
572 if (ZScriptVersion::gc_arrays())
19688 {
19689
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (auto array = checkArray(ptr, true))
19690 6 return !array->internal_expired;
19691
19692 return false;
19693 }
19694
19695 566 ptr /= 10000;
19696
19697
2/2
✓ Branch 0 taken 565 times.
✓ Branch 1 taken 1 times.
566 if(ptr < 0) //An object array?
19698 {
19699 1 int32_t objptr = -ptr;
19700 1 auto it = objectRAM.find(objptr);
19701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(it == objectRAM.end())
19702 return false;
19703 1 return true;
19704 }
19705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 565 times.
565 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //check global
19706 {
19707 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
19708
19709 if(gptr > game->globalRAM.size())
19710 return false;
19711 else return game->globalRAM[gptr].Valid();
19712 }
19713 else
19714 {
19715 565 return localRAM[ptr].Valid();
19716 }
19717 587 }
19718
19719 587 void do_isvalidarray()
19720 {
19721 587 int32_t ptr = get_register(sarg1);
19722
19723 587 set_register(sarg1,is_valid_array(ptr) ? 10000 : 0);
19724 587 }
19725
19726 31487 void do_isvaliditem()
19727 {
19728 31487 int32_t IID = get_register(sarg1);
19729 //int32_t ct = items.Count();
19730
19731 //for ( int32_t j = items.Count()-1; j >= 0; --j )
19732
2/2
✓ Branch 0 taken 55605 times.
✓ Branch 1 taken 213 times.
55818 for(int32_t j = 0; j < items.Count(); j++)
19733 //for(int32_t j = 0; j < ct; j++)
19734
2/2
✓ Branch 0 taken 31274 times.
✓ Branch 1 taken 24331 times.
55605 if(items.spr(j)->getUID() == IID)
19735 {
19736 31274 set_register(sarg1, 10000);
19737 31274 return;
19738 }
19739
19740 213 set_register(sarg1, 0);
19741 31487 }
19742
19743 11754119 void do_isvalidnpc()
19744 {
19745 11754119 int32_t UID = get_register(sarg1);
19746 //for ( int32_t j = guys.Count()-1; j >= 0; --j )
19747 //int32_t ct = guys.Count();
19748
19749
2/2
✓ Branch 0 taken 34202049 times.
✓ Branch 1 taken 112140 times.
34314189 for(int32_t j = 0; j < guys.Count(); j++)
19750 //for(int32_t j = 0; j < ct; j++)
19751
2/2
✓ Branch 0 taken 11641979 times.
✓ Branch 1 taken 22560070 times.
34202049 if(guys.spr(j)->getUID() == UID)
19752 {
19753 11641979 set_register(sarg1, 10000);
19754 11641979 return;
19755 }
19756
19757 112140 set_register(sarg1, 0);
19758 11754119 }
19759
19760 1205956 void do_isvalidlwpn()
19761 {
19762 1205956 int32_t WID = get_register(sarg1);
19763 //int32_t ct = Lwpns.Count();
19764
19765 //for ( int32_t j = Lwpns.Count()-1; j >= 0; --j )
19766
2/2
✓ Branch 0 taken 3080447 times.
✓ Branch 1 taken 590865 times.
3671312 for(int32_t j = 0; j < Lwpns.Count(); j++)
19767 //for(int32_t j = 0; j < ct; j++)
19768
2/2
✓ Branch 0 taken 2465356 times.
✓ Branch 1 taken 615091 times.
3080447 if(Lwpns.spr(j)->getUID() == WID)
19769 {
19770 615091 set_register(sarg1, 10000);
19771 615091 return;
19772 }
19773
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 590865 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
590865 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
19774 {
19775 set_register(sarg1, 10000);
19776 return;
19777 }
19778 590865 set_register(sarg1, 0);
19779 1205956 }
19780
19781 160009 void do_isvalidewpn()
19782 {
19783 160009 int32_t WID = get_register(sarg1);
19784
19785
2/2
✓ Branch 0 taken 961177 times.
✓ Branch 1 taken 23757 times.
984934 for(int32_t j = 0; j < Ewpns.Count(); j++)
19786
2/2
✓ Branch 0 taken 824925 times.
✓ Branch 1 taken 136252 times.
961177 if(Ewpns.spr(j)->getUID() == WID)
19787 {
19788 136252 set_register(sarg1, 10000);
19789 136252 return;
19790 }
19791 // unsure how an ewpn would be lifted, but, checking just to be safe
19792
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23757 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
23757 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
19793 {
19794 set_register(sarg1, 10000);
19795 return;
19796 }
19797 23757 set_register(sarg1, 0);
19798 160009 }
19799
19800 void do_lwpnmakeangular()
19801 {
19802 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19803 {
19804 if (!LwpnH::getWeapon()->angular)
19805 {
19806 double vx;
19807 double vy;
19808 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
19809 {
19810 case l_up:
19811 case l_down:
19812 case left:
19813 vx = -1.0*((weapon*)s)->step;
19814 break;
19815 case r_down:
19816 case r_up:
19817 case right:
19818 vx = ((weapon*)s)->step;
19819 break;
19820
19821 default:
19822 vx = 0;
19823 break;
19824 }
19825 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
19826 {
19827 case l_up:
19828 case r_up:
19829 case up:
19830 vy = -1.0*((weapon*)s)->step;
19831 break;
19832 case l_down:
19833 case r_down:
19834 case down:
19835 vy = ((weapon*)s)->step;
19836 break;
19837
19838 default:
19839 vy = 0;
19840 break;
19841 }
19842 LwpnH::getWeapon()->angular = true;
19843 LwpnH::getWeapon()->angle=atan2(vy, vx);
19844 LwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
19845 LwpnH::getWeapon()->doAutoRotate();
19846 }
19847 }
19848 }
19849
19850 void do_lwpnmakedirectional()
19851 {
19852 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19853 {
19854 if (LwpnH::getWeapon()->angular)
19855 {
19856 LwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(LwpnH::getWeapon()->angle)));
19857 LwpnH::getWeapon()->angular = false;
19858 LwpnH::getWeapon()->doAutoRotate(true);
19859 }
19860 }
19861 }
19862
19863 void do_ewpnmakeangular()
19864 {
19865 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
19866 {
19867 if (!EwpnH::getWeapon()->angular)
19868 {
19869 double vx;
19870 double vy;
19871 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
19872 {
19873 case l_up:
19874 case l_down:
19875 case left:
19876 vx = -1.0*((weapon*)s)->step;
19877 break;
19878 case r_down:
19879 case r_up:
19880 case right:
19881 vx = ((weapon*)s)->step;
19882 break;
19883
19884 default:
19885 vx = 0;
19886 break;
19887 }
19888 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
19889 {
19890 case l_up:
19891 case r_up:
19892 case up:
19893 vy = -1.0*((weapon*)s)->step;
19894 break;
19895 case l_down:
19896 case r_down:
19897 case down:
19898 vy = ((weapon*)s)->step;
19899 break;
19900
19901 default:
19902 vy = 0;
19903 break;
19904 }
19905 EwpnH::getWeapon()->angular = true;
19906 EwpnH::getWeapon()->angle=atan2(vy, vx);
19907 EwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
19908 EwpnH::getWeapon()->doAutoRotate();
19909 }
19910 }
19911 }
19912
19913 void do_ewpnmakedirectional()
19914 {
19915 if(EwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19916 {
19917 if (EwpnH::getWeapon()->angular)
19918 {
19919 EwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(EwpnH::getWeapon()->angle)));
19920 EwpnH::getWeapon()->angular = false;
19921 EwpnH::getWeapon()->doAutoRotate(true);
19922 }
19923 }
19924 }
19925
19926 19653 void do_lwpnusesprite(const bool v)
19927 {
19928 19653 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19929
19930
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19931 return;
19932
19933
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19934 19653 LwpnH::getWeapon()->LOADGFX(ID);
19935 19653 }
19936
19937 208946 void do_ewpnusesprite(const bool v)
19938 {
19939 208946 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19940
19941
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19942 return;
19943
19944
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
19945 208946 EwpnH::getWeapon()->LOADGFX(ID);
19946 208946 }
19947
19948 void do_portalusesprite()
19949 {
19950 int32_t ID = get_register(sarg1) / 10000;
19951
19952 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19953 return;
19954
19955 if(portal* p = checkPortal(ri->portalref))
19956 p->LOADGFX(ID);
19957 }
19958
19959 void do_clearsprites(const bool v)
19960 {
19961 int32_t spritelist = SH::get_arg(sarg1, v) / 10000;
19962
19963 if(BC::checkBounds(spritelist, 0, 5) != SH::_NoError)
19964 return;
19965
19966 switch(spritelist)
19967 {
19968 case 0:
19969 guys.clear();
19970 break;
19971
19972 case 1:
19973 items.clear();
19974 break;
19975
19976 case 2:
19977 Ewpns.clear();
19978 break;
19979
19980 case 3:
19981 Lwpns.clear();
19982 Hero.reset_hookshot();
19983 break;
19984
19985 case 4:
19986 decorations.clear();
19987 break;
19988
19989 case 5:
19990 particles.clear();
19991 break;
19992 }
19993 }
19994
19995 1452537 void do_loadlweapon(const bool v)
19996 {
19997 1452537 int32_t index = SH::get_arg(sarg1, v) / 10000;
19998
19999
2/2
✓ Branch 0 taken 16630 times.
✓ Branch 1 taken 1435907 times.
1452537 if(BC::checkLWeaponIndex(index) != SH::_NoError)
20000 16630 ri->lwpn = 0; //MAX_DWORD; //Now NULL
20001 else
20002 {
20003 1435907 ri->lwpn = Lwpns.spr(index)->getUID();
20004 // This is too trivial to log. -L
20005 }
20006 1452537 }
20007
20008 4712412 void do_loadeweapon(const bool v)
20009 {
20010 4712412 int32_t index = SH::get_arg(sarg1, v) / 10000;
20011
20012
2/2
✓ Branch 0 taken 68863 times.
✓ Branch 1 taken 4643549 times.
4712412 if(BC::checkEWeaponIndex(index) != SH::_NoError)
20013 68863 ri->ewpn = 0; //MAX_DWORD; //Now NULL
20014 else
20015 {
20016 4643549 ri->ewpn = Ewpns.spr(index)->getUID();
20017 }
20018 4712412 }
20019
20020 585769 void do_loaditem(const bool v)
20021 {
20022 585769 int32_t index = SH::get_arg(sarg1, v) / 10000;
20023
20024
2/2
✓ Branch 0 taken 298944 times.
✓ Branch 1 taken 286825 times.
585769 if(BC::checkItemIndex(index) != SH::_NoError)
20025 298944 ri->itemref = 0; //MAX_DWORD; //Now NULL
20026 else
20027 {
20028 286825 ri->itemref = items.spr(index)->getUID();
20029 }
20030 585769 }
20031
20032
20033 5620654 void do_loaditemdata(const bool v)
20034 {
20035 5620654 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20036
20037 //I *think* this is the right check ~Joe
20038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5620654 times.
5620654 if(BC::checkItemID(ID) != SH::_NoError)
20039 {
20040 ri->idata = -1; //new null value
20041 return;
20042 }
20043 5620654 ri->idata = ID;
20044 5620654 }
20045
20046 27870027 void do_loadnpc(const bool v)
20047 {
20048 27870027 int32_t index = SH::get_arg(sarg1, v) / 10000;
20049
20050
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 27869823 times.
27870027 if(BC::checkGuyIndex(index) != SH::_NoError)
20051 204 ri->guyref = 0; // MAX_DWORD;
20052 else
20053 {
20054 27869823 ri->guyref = guys.spr(index)->getUID();
20055 }
20056 27870027 }
20057
20058 1173684 void FFScript::do_loaddmapdata(const bool v)
20059 {
20060 1173684 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20061
20062
2/4
✓ Branch 0 taken 1173684 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1173684 times.
1173684 if ( ID < 0 || ID > 511 )
20063 {
20064 Z_scripterrlog("Invalid DMap ID passed to Game->LoadDMapData(): %d\n", ID);
20065 ri->dmapsref = MAX_DWORD;
20066 }
20067 1173684 else ri->dmapsref = ID;
20068 1173684 }
20069
20070 3 void FFScript::do_load_active_subscreendata(const bool v)
20071 {
20072 3 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20073
20074
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 if(ID == -1 || (unsigned(ID) < subscreens_active.size() && unsigned(ID) < 256))
20075 {
20076 3 ri->subdataref = get_subref(ID, sstACTIVE);
20077 3 }
20078 else
20079 {
20080 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadASubData(): %d\n", ID);
20081 ri->subdataref = 0;
20082 }
20083 3 ri->d[rEXP1] = ri->subdataref;
20084 3 }
20085 void FFScript::do_load_passive_subscreendata(const bool v)
20086 {
20087 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20088
20089 if(ID == -1 || (unsigned(ID) < subscreens_passive.size() && unsigned(ID) < 256))
20090 {
20091 ri->subdataref = get_subref(ID, sstPASSIVE);
20092 }
20093 else
20094 {
20095 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadPSubData(): %d\n", ID);
20096 ri->subdataref = 0;
20097 }
20098 ri->d[rEXP1] = ri->subdataref;
20099 }
20100 void FFScript::do_load_overlay_subscreendata(const bool v)
20101 {
20102 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20103
20104 if(ID == -1 || (unsigned(ID) < subscreens_overlay.size() && unsigned(ID) < 256))
20105 {
20106 ri->subdataref = get_subref(ID, sstOVERLAY);
20107 }
20108 else
20109 {
20110 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadOSubData(): %d\n", ID);
20111 ri->subdataref = 0;
20112 }
20113 ri->d[rEXP1] = ri->subdataref;
20114 }
20115 3 void FFScript::do_load_subscreendata(const bool v, const bool v2)
20116 {
20117 3 int32_t ty = SH::get_arg(sarg2, v2) / 10000;
20118
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 switch(ty)
20119 {
20120 case sstACTIVE:
20121 3 do_load_active_subscreendata(v);
20122 3 break;
20123 case sstPASSIVE:
20124 do_load_passive_subscreendata(v);
20125 break;
20126 case sstOVERLAY:
20127 do_load_overlay_subscreendata(v);
20128 break;
20129 default:
20130 {
20131 Z_scripterrlog("Invalid Subscreen Type passed to ???: %d\n", ty);
20132 ri->subdataref = 0;
20133 break;
20134 }
20135 }
20136 3 ri->d[rEXP1] = ri->subdataref;
20137 3 }
20138
20139 931 void FFScript::do_loadrng()
20140 {
20141 931 auto rng = user_rngs.create();
20142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 931 times.
931 if (!rng)
20143 {
20144 ri->d[rEXP1] = 0;
20145 return;
20146 }
20147
20148 931 int q = script_object_ids_by_type[script_object_type::rng].size() - 1;
20149 931 rng->gen = &script_rnggens[q];
20150 931 ri->rngref = rng->id;
20151 931 ri->d[rEXP1] = rng->id;
20152 931 }
20153
20154 void FFScript::do_loaddirectory()
20155 {
20156 int32_t arrayptr = get_register(sarg1);
20157 string user_path;
20158 ArrayH::getString(arrayptr, user_path, 2048);
20159
20160 std::string resolved_path;
20161 if (auto r = parse_user_path(user_path, false); !r)
20162 {
20163 scripting_log_error_with_context("Error: {}", r.error());
20164 return;
20165 } else resolved_path = r.value();
20166
20167 if (checkPath(resolved_path.c_str(), true))
20168 {
20169 ri->directoryref = user_dirs.get_free();
20170 if(!ri->directoryref) return;
20171 user_dir* d = checkDir(ri->directoryref, true);
20172 set_register(sarg1, ri->directoryref);
20173 d->setPath(resolved_path.c_str());
20174 return;
20175 }
20176
20177 scripting_log_error_with_context("Path '{}' points to a file; must point to a directory!", resolved_path);
20178 ri->directoryref = 0;
20179 set_register(sarg1, 0);
20180 }
20181
20182 void FFScript::do_loadstack()
20183 {
20184 ri->stackref = user_stacks.get_free();
20185 ri->d[rEXP1] = ri->stackref;
20186 }
20187
20188 10 void FFScript::do_loaddropset(const bool v)
20189 {
20190 10 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20191
20192
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( ID < 0 || ID > MAXITEMDROPSETS )
20193 {
20194 scripting_log_error_with_context("Invalid Dropset ID: {}", ID);
20195 ri->dropsetref = MAX_DWORD;
20196 }
20197
20198 10 else ri->dropsetref = ID;
20199 10 }
20200
20201 void FFScript::do_loadbottle(const bool v)
20202 {
20203 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20204
20205 if ( ID < 1 || ID > 64 )
20206 {
20207 scripting_log_error_with_context("Invalid BottleType ID: {}", ID);
20208 ri->bottletyperef = 0;
20209 }
20210 else ri->bottletyperef = ID;
20211 }
20212
20213 void FFScript::do_loadbottleshop(const bool v)
20214 {
20215 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20216
20217 if ( ID < 0 || ID > 255 )
20218 {
20219 scripting_log_error_with_context("Invalid BottleShopType ID: {}", ID);
20220 ri->bottleshopref = 0;
20221 }
20222 else ri->bottleshopref = ID+1;
20223 }
20224 137117 void FFScript::do_loadgenericdata(const bool v)
20225 {
20226 137117 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20227
20228
2/4
✓ Branch 0 taken 137117 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 137117 times.
137117 if ( ID < 1 || ID > NUMSCRIPTSGENERIC )
20229 {
20230 scripting_log_error_with_context("Invalid GenericData ID: {}", ID);
20231 ri->genericdataref = 0;
20232 }
20233 137117 else ri->genericdataref = ID;
20234 137117 }
20235
20236 223 void FFScript::do_create_paldata()
20237 {
20238 223 ri->paldataref = user_paldatas.get_free();
20239 223 ri->d[rEXP1] = ri->paldataref;
20240 223 }
20241
20242 11 void FFScript::do_create_paldata_clr()
20243 {
20244 11 ri->paldataref = user_paldatas.get_free();
20245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (ri->paldataref > 0)
20246 {
20247 11 user_paldata& pd = user_paldatas[ri->paldataref];
20248 11 int32_t clri = get_register(sarg1);
20249
20250 11 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
20251
20252 11 c.r = vbound(c.r, 0, scripting_max_color_val);
20253 11 c.g = vbound(c.g, 0, scripting_max_color_val);
20254 11 c.b = vbound(c.b, 0, scripting_max_color_val);
20255
20256
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 11 times.
2651 for (int32_t q = 0; q < 240; ++q)
20257 2640 pd.set_color(q, c);
20258 11 }
20259 11 ri->d[rEXP1] = ri->paldataref;
20260 11 }
20261
20262 void FFScript::do_mix_clr()
20263 {
20264 int32_t clr_start = SH::read_stack(ri->sp + 3);
20265 int32_t clr_end = SH::read_stack(ri->sp + 2);
20266 float percent = SH::read_stack(ri->sp + 1) / 10000.0;
20267 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20268
20269 RGB ref1c = _RGB((clr_start >> 16) & 0xFF, (clr_start >> 8) & 0xFF, clr_start & 0xFF);
20270 RGB ref2c = _RGB((clr_end >> 16) & 0xFF, (clr_end >> 8) & 0xFF, clr_end & 0xFF);
20271 RGB outputc = user_paldata::mix_color(ref1c, ref2c, percent, color_space);
20272
20273 int32_t r = vbound(outputc.r, 0, scripting_max_color_val);
20274 int32_t g = vbound(outputc.g, 0, scripting_max_color_val);
20275 int32_t b = vbound(outputc.b, 0, scripting_max_color_val);
20276
20277 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20278 }
20279
20280 void FFScript::do_create_rgb_hex()
20281 {
20282 int32_t hexrgb = get_register(sarg1);
20283
20284 int32_t r = (hexrgb >> 16) & 0xFF;
20285 int32_t g = (hexrgb >> 8) & 0xFF;
20286 int32_t b = hexrgb & 0xFF;
20287
20288 if (scripting_use_8bit_colors)
20289 {
20290 r = vbound(r, 0, 255);
20291 g = vbound(g, 0, 255);
20292 b = vbound(b, 0, 255);
20293 }
20294 else
20295 {
20296 r = vbound(r / 4, 0, 63);
20297 g = vbound(g / 4, 0, 63);
20298 b = vbound(b / 4, 0, 63);
20299 }
20300
20301 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20302 }
20303
20304 11 void FFScript::do_create_rgb()
20305 {
20306 11 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
20307 11 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
20308 11 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
20309
20310 11 int max_value = scripting_max_color_val;
20311
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
11 if (unsigned(r) > max_value || unsigned(g) > max_value || unsigned(b) > max_value)
20312 {
20313 1 scripting_log_error_with_context("R/G/B values should range from 0-{}, got: {} {} {}", max_value, r, g, b);
20314 1 }
20315
20316 11 r = vbound(r, 0, max_value);
20317 11 g = vbound(g, 0, max_value);
20318 11 b = vbound(b, 0, max_value);
20319
20320 11 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20321 11 }
20322
20323 void FFScript::do_convert_from_rgb()
20324 {
20325 int32_t buf = SH::read_stack(ri->sp + 2) / 10000;
20326 int32_t clri = SH::read_stack(ri->sp + 1);
20327 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20328
20329 ArrayManager am(buf);
20330 if (am.invalid()) return;
20331 int32_t zscript_array_size = am.size();
20332 int32_t target_size;
20333
20334 switch (color_space)
20335 {
20336 case user_paldata::CSPACE_CMYK:
20337 target_size = 4;
20338 break;
20339 default:
20340 target_size = 3;
20341 }
20342
20343 if (zscript_array_size < target_size)
20344 {
20345 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
20346 return;
20347 }
20348
20349 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
20350 double convert[4];
20351 user_paldata::RGBTo(c, convert, color_space);
20352
20353 for (int32_t q = 0; q < target_size; ++q)
20354 {
20355 am.set(q, int32_t(convert[q]*10000));
20356 }
20357
20358 return;
20359 }
20360
20361 void FFScript::do_convert_to_rgb()
20362 {
20363 int32_t buf = SH::read_stack(ri->sp + 1) / 10000;
20364 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20365
20366 ArrayManager am(buf);
20367 if (am.invalid()) return;
20368 int32_t zscript_array_size = am.size();
20369 int32_t target_size;
20370
20371 switch (color_space)
20372 {
20373 case user_paldata::CSPACE_CMYK:
20374 target_size = 4;
20375 break;
20376 default:
20377 target_size = 3;
20378 }
20379
20380 if (zscript_array_size < target_size)
20381 {
20382 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
20383 return;
20384 }
20385
20386 double convert[4];
20387 for (int32_t q = 0; q < target_size; ++q)
20388 {
20389 convert[q] = am.get(q) / 10000.0;
20390 }
20391 RGB c = user_paldata::RGBFrom(convert, color_space);
20392
20393 ri->d[rEXP1] = (c.r << 16) | (c.g << 8) | c.b;
20394 }
20395
20396 24 void FFScript::do_paldata_load_level()
20397 {
20398
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (user_paldata* pd = checkPalData(ri->paldataref))
20399 {
20400 24 int32_t lvl = get_register(sarg1) / 10000;
20401 //Load CSets 2-4
20402 24 pd->load_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20403 24 pd->load_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20404 24 pd->load_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20405 //Load CSet 9
20406 24 pd->load_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20407 //Load 1, 5, 7, 8
20408 24 pd->load_cset(1, lvl * pdLEVEL + poNEWCSETS);
20409 24 pd->load_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20410 24 pd->load_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20411 24 pd->load_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20412 24 }
20413 24 return;
20414 }
20415
20416 87 void FFScript::do_paldata_load_sprite()
20417 {
20418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 if (user_paldata* pd = checkPalData(ri->paldataref))
20419 {
20420 87 int32_t page = get_register(sarg1) / 10000;
20421
20422 87 int32_t pageoffset = 0;
20423
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
87 switch (page)
20424 {
20425 87 case 0: pageoffset += 0; break;
20426 case 1: pageoffset += 15; break;
20427 default:
20428 scripting_log_error_with_context("Invalid page: {}. Valid pages are 0 or 1. Aborting.", page);
20429 return;
20430 }
20431
2/2
✓ Branch 0 taken 1305 times.
✓ Branch 1 taken 87 times.
1392 for (int32_t q = 0; q < 15; ++q)
20432 {
20433 1305 pd->load_cset(q, poSPRITE255 + pageoffset + q);
20434 1305 }
20435 87 }
20436 87 return;
20437 87 }
20438
20439 92 void FFScript::do_paldata_load_main()
20440 {
20441
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 if (user_paldata* pd = checkPalData(ri->paldataref))
20442 {
20443
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 92 times.
1564 for (int32_t q = 0; q <= 15; ++q)
20444 {
20445 1472 pd->load_cset_main(q);
20446 1472 }
20447 92 }
20448 92 return;
20449 }
20450
20451 void FFScript::do_paldata_load_cycle()
20452 {
20453 if (user_paldata* pd = checkPalData(ri->paldataref))
20454 {
20455 int32_t lvl = get_register(sarg1) / 10000;
20456 for (int32_t q = 4; q <= 12; ++q)
20457 {
20458 pd->load_cset(q, lvl * pdLEVEL + poLEVEL + q);
20459 }
20460 }
20461 return;
20462 }
20463
20464 void FFScript::do_paldata_load_bitmap()
20465 {
20466 if (user_paldata* pd = checkPalData(ri->paldataref))
20467 {
20468 int32_t pathptr = get_register(sarg1);
20469 string user_path, str;
20470 ArrayH::getString(pathptr, user_path, 256);
20471
20472 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
20473 {
20474 if (auto r = parse_user_path(user_path, true); !r)
20475 {
20476 scripting_log_error_with_context("Error: {}", r.error());
20477 return;
20478 } else str = r.value();
20479 }
20480 else
20481 {
20482 str = user_path;
20483 regulate_path(str);
20484 }
20485
20486 if (str.empty())
20487 {
20488 al_trace("String pointer is null! Internal error. \n");
20489 return;
20490 }
20491
20492 PALETTE tempPal;
20493 get_palette(tempPal);
20494 if (checkPath(str.c_str(), false))
20495 {
20496 BITMAP* bmp = load_bitmap(str.c_str(), tempPal);
20497 if (!bmp)
20498 {
20499 Z_scripterrlog("LoadBitmapPalette() failed to load image file %s.\n", str.c_str());
20500 }
20501 else
20502 {
20503 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
20504 {
20505 pd->colors[q] = tempPal[q];
20506 set_bit(pd->colors_used, q, true);
20507 }
20508 }
20509 destroy_bitmap(bmp);
20510 }
20511 else
20512 {
20513 Z_scripterrlog("Failed to load image file: %s. File not found.\n", str.c_str());
20514 }
20515 }
20516 return;
20517 }
20518
20519 370 void FFScript::do_paldata_write_level()
20520 {
20521
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (user_paldata* pd = checkPalData(ri->paldataref))
20522 {
20523 370 int32_t lvl = get_register(sarg1) / 10000;
20524 370 bool changed = false;
20525 //Write CSets 2-4
20526
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
20527 {
20528 360 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20529 360 changed = true;
20530 360 }
20531
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
20532 {
20533 360 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20534 360 changed = true;
20535 360 }
20536
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
20537 {
20538 360 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20539 360 changed = true;
20540 360 }
20541 //Write CSet 9
20542
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
20543 {
20544 360 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20545 360 changed = true;
20546 360 }
20547 //Write 1, 5, 7, 8
20548
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
20549 {
20550 360 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
20551 360 changed = true;
20552 360 }
20553
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
20554 {
20555 360 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20556 360 changed = true;
20557 360 }
20558
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
20559 {
20560 360 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20561 360 changed = true;
20562 360 }
20563
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
20564 {
20565 360 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20566 360 changed = true;
20567 360 }
20568
20569
4/4
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 350 times.
370 if (changed && DMaps[cur_dmap].color == lvl)
20570 {
20571 350 loadlvlpal(lvl);
20572 350 currcset = lvl;
20573
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
350 if (darkroom && !get_qr(qr_NEW_DARKROOM))
20574 {
20575 if (get_qr(qr_FADE))
20576 {
20577 interpolatedfade();
20578 }
20579 else
20580 {
20581 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
20582 }
20583 }
20584 350 }
20585 370 }
20586 370 return;
20587 }
20588
20589 void FFScript::do_paldata_write_levelcset()
20590 {
20591 if (user_paldata* pd = checkPalData(ri->paldataref))
20592 {
20593 int32_t lvl = get_register(sarg1) / 10000;
20594 int32_t cs = get_register(sarg2) / 10000;
20595
20596 bool changed = false;
20597
20598 switch (cs)
20599 {
20600 case 1:
20601 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
20602 {
20603 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
20604 changed = true;
20605 }
20606 break;
20607 case 2:
20608 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
20609 {
20610 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20611 changed = true;
20612 }
20613 break;
20614 case 3:
20615 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
20616 {
20617 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20618 changed = true;
20619 }
20620 break;
20621 case 4:
20622 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
20623 {
20624 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20625 changed = true;
20626 }
20627 break;
20628 case 5:
20629 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
20630 {
20631 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20632 changed = true;
20633 }
20634 break;
20635 case 7:
20636 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
20637 {
20638 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20639 changed = true;
20640 }
20641 break;
20642 case 8:
20643 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
20644 {
20645 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20646 changed = true;
20647 }
20648 break;
20649 case 9:
20650 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
20651 {
20652 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20653 changed = true;
20654 }
20655 break;
20656 default:
20657 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteLevelCSet()'. Level palettes can use CSets 1, 2, 3, 4, 5, 7, 8, 9.\n", cs);
20658 return;
20659 }
20660
20661 if (changed && DMaps[cur_dmap].color == lvl)
20662 {
20663 loadlvlpal(lvl);
20664 if (darkroom && !get_qr(qr_NEW_DARKROOM))
20665 {
20666 if (get_qr(qr_FADE))
20667 {
20668 interpolatedfade();
20669 }
20670 else
20671 {
20672 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
20673 }
20674 }
20675 currcset = lvl;
20676 }
20677 }
20678 }
20679
20680 31 void FFScript::do_paldata_write_sprite()
20681 {
20682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (user_paldata* pd = checkPalData(ri->paldataref))
20683 {
20684 31 int32_t page = get_register(sarg1) / 10000;
20685
20686 31 int32_t pageoffset = 0;
20687
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 switch (page)
20688 {
20689 31 case 0: pageoffset += 0; break;
20690 case 1: pageoffset += 15; break;
20691 default:
20692 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpritePalette(). Valid pages are 0 or 1. Aborting.\n", page);
20693 return;
20694 }
20695 31 bool changed6 = false;
20696 31 bool changed14 = false;
20697
2/2
✓ Branch 0 taken 465 times.
✓ Branch 1 taken 31 times.
496 for (int32_t q = 0; q < 15; ++q)
20698 {
20699
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 25 times.
465 if (pd->check_cset(q, poSPRITE255 + pageoffset + q))
20700 {
20701 25 pd->write_cset(q, poSPRITE255 + pageoffset + q);
20702
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal6)
20703 {
20704 changed6 = true;
20705 }
20706
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal14)
20707 {
20708 changed14 = true;
20709 }
20710 25 }
20711 465 }
20712
20713 //If either sprite palette has been changed, update the main palette
20714
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 if (changed6 || changed14)
20715 {
20716 if (changed6)
20717 {
20718 loadpalset(6, poSPRITE255 + currspal6, false);
20719 }
20720 if (changed14)
20721 {
20722 loadpalset(14, poSPRITE255 + currspal14, false);
20723 }
20724
20725 if (isUserTinted()) {
20726 restoreTint();
20727 }
20728 }
20729 31 }
20730 31 return;
20731 31 }
20732
20733 void FFScript::do_paldata_write_spritecset()
20734 {
20735 if (user_paldata* pd = checkPalData(ri->paldataref))
20736 {
20737 int32_t page = get_register(sarg1) / 10000;
20738 int32_t cs = get_register(sarg2) / 10000;
20739
20740 int32_t pageoffset = 0;
20741 switch (page)
20742 {
20743 case 0: pageoffset += 0; break;
20744 case 1: pageoffset += 15; break;
20745 default:
20746 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpriteCSet(). Valid pages are 0 or 1. Aborting.\n", page);
20747 return;
20748 }
20749 bool changed6 = false;
20750 bool changed14 = false;
20751 if (unsigned(cs) > 15)
20752 {
20753 Z_scripterrlog("Invalid CSet (%d) passed to paldata->WriteSpriteCSet(). Valid CSets are 0-15. Aborting.\n", cs);
20754 return;
20755 }
20756 if (pd->check_cset(cs, poSPRITE255 + pageoffset + cs))
20757 {
20758 pd->write_cset(cs, poSPRITE255 + pageoffset + cs);
20759 if (pageoffset + cs == currspal6)
20760 {
20761 changed6 = true;
20762 }
20763 if (pageoffset + cs == currspal14)
20764 {
20765 changed14 = true;
20766 }
20767 }
20768
20769 //If either sprite palette has been changed, update the main palette
20770 if (changed6 || changed14)
20771 {
20772 if (changed6)
20773 {
20774 loadpalset(6, poSPRITE255 + currspal6, false);
20775 }
20776 if (changed14)
20777 {
20778 loadpalset(14, poSPRITE255 + currspal14, false);
20779 }
20780
20781 if (isUserTinted()) {
20782 restoreTint();
20783 }
20784 }
20785 }
20786 return;
20787 }
20788
20789 1064 void FFScript::do_paldata_write_main()
20790 {
20791
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 if (user_paldata* pd = checkPalData(ri->paldataref))
20792 {
20793 1064 bool changed = false;
20794
2/2
✓ Branch 0 taken 17024 times.
✓ Branch 1 taken 1064 times.
18088 for (int32_t q = 0; q <= 15; ++q)
20795 {
20796
2/2
✓ Branch 0 taken 11363 times.
✓ Branch 1 taken 5661 times.
17024 if (pd->check_cset_main(q))
20797 {
20798 5661 pd->write_cset_main(q);
20799 5661 changed = true;
20800 5661 }
20801 17024 }
20802
20803
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 732 times.
1064 if (changed)
20804 {
20805 732 refreshpal = true;
20806 732 }
20807 1064 }
20808 1064 return;
20809 }
20810
20811 130 void FFScript::do_paldata_write_maincset()
20812 {
20813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if (user_paldata* pd = checkPalData(ri->paldataref))
20814 {
20815 130 int32_t cs = get_register(sarg1) / 10000;
20816
20817 130 bool changed = false;
20818
20819
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (unsigned(cs) < 16)
20820 {
20821
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (pd->check_cset_main(cs))
20822 {
20823 130 pd->write_cset_main(cs);
20824 130 changed = true;
20825 130 }
20826 130 }
20827 else
20828 {
20829 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteMainCSet()'. Valid csets are 0-15. Aborting.\n", cs);
20830 return;
20831 }
20832
20833
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (changed)
20834 {
20835 130 refreshpal = true;
20836 130 }
20837 130 }
20838 130 }
20839
20840 void FFScript::do_paldata_write_cycle()
20841 {
20842 if (user_paldata* pd = checkPalData(ri->paldataref))
20843 {
20844 int32_t lvl = get_register(sarg1) / 10000;
20845 for (int32_t q = 4; q <= 12; ++q)
20846 {
20847 if (pd->check_cset(q, lvl * pdLEVEL + poLEVEL + q))
20848 {
20849 pd->write_cset(q, lvl * pdLEVEL + poLEVEL + q);
20850 }
20851 }
20852 }
20853 return;
20854 }
20855
20856 void FFScript::do_paldata_write_cyclecset()
20857 {
20858 if (user_paldata* pd = checkPalData(ri->paldataref))
20859 {
20860 int32_t lvl = get_register(sarg1) / 10000;
20861 int32_t cs = get_register(sarg2) / 10000;
20862
20863 bool changed = false;
20864
20865 switch (cs)
20866 {
20867 case 4:
20868 case 5:
20869 case 6:
20870 case 7:
20871 case 8:
20872 case 9:
20873 case 10:
20874 case 11:
20875 case 12:
20876 if (pd->check_cset(cs, lvl * pdLEVEL + poLEVEL + cs))
20877 {
20878 pd->write_cset(cs, lvl * pdLEVEL + poLEVEL + cs);
20879 changed = true;
20880 }
20881 break;
20882 default:
20883 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteCycleCSet()'. Cycle palettes use CSets 4-12.\n", cs);
20884 return;
20885 }
20886
20887 if (changed && DMaps[cur_dmap].color == lvl)
20888 {
20889 loadlvlpal(lvl);
20890 currcset = lvl;
20891 }
20892 }
20893 }
20894
20895 void FFScript::do_paldata_colorvalid()
20896 {
20897 if (user_paldata* pd = checkPalData(ri->paldataref))
20898 {
20899 int32_t ind = get_register(sarg1) / 10000;
20900 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20901 {
20902 Z_scripterrlog("Invalid color index (%d) passed to paldata->ColorValid(). Valid indices are 0-255.\n", ind);
20903 set_register(sarg1, 0);
20904 return;
20905 }
20906
20907 if (get_bit(pd->colors_used, ind))
20908 {
20909 set_register(sarg1, 10000);
20910 }
20911 else
20912 {
20913 set_register(sarg1, 0);
20914 }
20915 }
20916 }
20917
20918 void FFScript::do_paldata_clearcolor()
20919 {
20920 if (user_paldata* pd = checkPalData(ri->paldataref))
20921 {
20922 int32_t ind = get_register(sarg1) / 10000;
20923 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20924 {
20925 Z_scripterrlog("Invalid color index (%d) passed to paldata->ClearColor(). Valid indices are 0-255. Aborting.\n", ind);
20926 return;
20927 }
20928 set_bit(pd->colors_used, ind, false);
20929 }
20930 }
20931
20932 void FFScript::do_paldata_clearcset()
20933 {
20934 if (user_paldata* pd = checkPalData(ri->paldataref))
20935 {
20936 int32_t cs = get_register(sarg1) / 10000;
20937 if (unsigned(cs) > 15)
20938 {
20939 Z_scripterrlog("Invalid cset (%d) passed to paldata->ClearCSet(). Valid csets are 0-15. Aborting.\n", cs);
20940 return;
20941 }
20942 for (int32_t q = 0; q < 16; ++q)
20943 {
20944 set_bit(pd->colors_used, CSET(cs) + q, false);
20945 }
20946 }
20947 }
20948
20949 int32_t FFScript::do_paldata_getrgb(user_paldata* pd, int32_t index, int32_t c)
20950 {
20951 if (pd)
20952 {
20953 int32_t ind = index;
20954 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20955 {
20956 scripting_log_error_with_context("Invalid color index ({}). Valid indices are 0-255.", ind);
20957 return -10000;
20958 }
20959 if (!get_bit(pd->colors_used, ind))
20960 {
20961 scripting_log_error_with_context("Tried to access unused color {}.", ind);
20962 return -10000;
20963 }
20964 switch (c)
20965 {
20966 case 0:
20967 return pd->colors[ind].r * 10000;
20968 case 1:
20969 return pd->colors[ind].g * 10000;
20970 case 2:
20971 return pd->colors[ind].b * 10000;
20972 }
20973 }
20974
20975 return -10000;
20976 }
20977
20978 void FFScript::do_paldata_setrgb(user_paldata* pd, int32_t index, int32_t val, int32_t c)
20979 {
20980 if (pd)
20981 {
20982 int32_t ind = index;
20983 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20984 {
20985 scripting_log_error_with_context("Invalid color index ({}). Valid indices are 0-255. Aborting.", ind);
20986 return;
20987 }
20988 if (unsigned(val) > scripting_max_color_val)
20989 {
20990 scripting_log_error_with_context("RGB value({}) is out of range. RGB values range from 0 - {}.", val, scripting_max_color_val);
20991 val = vbound(val, 0, scripting_max_color_val);
20992 }
20993 if (!get_bit(pd->colors_used, ind))
20994 {
20995 scripting_log_error_with_context("Tried to access unused color {}.", ind);
20996 return;
20997 }
20998 switch (c)
20999 {
21000 case 0:
21001 pd->colors[ind].r = val;
21002 break;
21003 case 1:
21004 pd->colors[ind].g = val;
21005 break;
21006 case 2:
21007 pd->colors[ind].b = val;
21008 break;
21009 }
21010 }
21011 }
21012
21013 450 void FFScript::do_paldata_mix()
21014 {
21015 450 int32_t ref = SH::read_stack(ri->sp + 4);
21016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd = checkPalData(ref))
21017 {
21018 450 int32_t ref1 = SH::read_stack(ri->sp + 3);
21019 450 int32_t ref2 = SH::read_stack(ri->sp + 2);
21020 450 double percent = SH::read_stack(ri->sp + 1)/10000.0;
21021 450 int32_t color_space = SH::read_stack(ri->sp + 0)/10000;
21022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_start = checkPalData(ref1))
21023 {
21024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_end = checkPalData(ref2))
21025 {
21026 450 pd->mix(pd_start, pd_end, percent, color_space);
21027 450 }
21028 450 }
21029 450 }
21030 450 }
21031
21032 4781 void FFScript::do_paldata_mixcset()
21033 {
21034 4781 int32_t ref = SH::read_stack(ri->sp + 5);
21035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd = checkPalData(ref))
21036 {
21037 4781 int32_t ref1 = SH::read_stack(ri->sp + 4);
21038 4781 int32_t ref2 = SH::read_stack(ri->sp + 3);
21039 4781 int32_t cset = SH::read_stack(ri->sp + 2) / 10000;
21040 4781 double percent = SH::read_stack(ri->sp + 1) / 10000.0;
21041 4781 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
21042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_start = checkPalData(ref1))
21043 {
21044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_end = checkPalData(ref2))
21045 {
21046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (unsigned(cset) > 15)
21047 {
21048 Z_scripterrlog("CSet passed to 'paldata->MixCSet()' out of range. Valid CSets are 0-15\n");
21049 return;
21050 }
21051 4781 pd->mix(pd_start, pd_end, percent, color_space, CSET(cset), CSET(cset) + 16);
21052 4781 }
21053 4781 }
21054 4781 }
21055 4781 }
21056
21057 void FFScript::do_paldata_copy()
21058 {
21059 if (user_paldata* pd = checkPalData(ri->paldataref))
21060 {
21061 int32_t ref_dest = get_register(sarg1);
21062 if (user_paldata* pd_dest = checkPalData(ref_dest))
21063 {
21064 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
21065 {
21066 pd_dest->colors[q] = pd->colors[q];
21067 }
21068 for (int32_t q = 0; q < PALDATA_BITSTREAM_SIZE; ++q)
21069 {
21070 pd_dest->colors_used[q] = pd->colors_used[q];
21071 }
21072 }
21073 }
21074 }
21075
21076 112 void FFScript::do_paldata_copycset()
21077 {
21078 112 ri->paldataref = SH::read_stack(ri->sp + 3);
21079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd = checkPalData(ri->paldataref))
21080 {
21081 112 int32_t ref_dest = SH::read_stack(ri->sp + 2);
21082 112 int32_t cs = SH::read_stack(ri->sp + 1) / 10000;
21083 112 int32_t cs_dest = SH::read_stack(ri->sp + 0) / 10000;
21084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd_dest = checkPalData(ref_dest))
21085 {
21086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (unsigned(cs) > 15)
21087 {
21088 Z_scripterrlog("Invalid CSet (%d) passed to paldata->CopyCSet(). Valid CSets are 0-15. Aborting.\n", cs);
21089 return;
21090 }
21091
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 112 times.
1904 for (int32_t q = 0; q < 16; ++q)
21092 {
21093 1792 pd_dest->colors[CSET(cs_dest) + q] = pd->colors[CSET(cs) + q];
21094 1792 set_bit(pd_dest->colors_used, CSET(cs_dest) + q, bool(get_bit(pd->colors_used, CSET(cs) + q)));
21095 1792 }
21096 112 }
21097 112 }
21098 112 }
21099
21100 //Loads a cset to paldata from memory
21101 1497 void user_paldata::load_cset(int32_t cset, int32_t dataset)
21102 {
21103 1497 byte* si = colordata + CSET(dataset) * 3;
21104
2/2
✓ Branch 0 taken 23952 times.
✓ Branch 1 taken 1497 times.
25449 for (int32_t q = 0; q < 16; ++q)
21105 {
21106 23952 int32_t ind = CSET(cset) + q;
21107 23952 colors[ind].r = scripting_read_pal_color(si[0]);
21108 23952 colors[ind].g = scripting_read_pal_color(si[1]);
21109 23952 colors[ind].b = scripting_read_pal_color(si[2]);
21110 23952 set_bit(colors_used, ind, true);
21111 23952 si += 3;
21112 23952 }
21113 1497 }
21114
21115 //Loads a cset to paldata from the main palette
21116 1472 void user_paldata::load_cset_main(int32_t cset)
21117 {
21118
2/2
✓ Branch 0 taken 23552 times.
✓ Branch 1 taken 1472 times.
25024 for (int32_t q = 0; q < 16; ++q)
21119 {
21120 23552 int32_t ind = CSET(cset) + q;
21121 23552 colors[ind].r = scripting_read_pal_color(RAMpal[ind].r);
21122 23552 colors[ind].g = scripting_read_pal_color(RAMpal[ind].g);
21123 23552 colors[ind].b = scripting_read_pal_color(RAMpal[ind].b);
21124 23552 set_bit(colors_used, ind, true);
21125 23552 }
21126 1472 }
21127
21128 //Writes to a memory cset from paldata
21129 2905 void user_paldata::write_cset(int32_t cset, int32_t dataset)
21130 {
21131 2905 byte* si = colordata + CSET(dataset) * 3;
21132
2/2
✓ Branch 0 taken 46480 times.
✓ Branch 1 taken 2905 times.
49385 for (int32_t q = 0; q < 16; ++q)
21133 {
21134 46480 int32_t ind = CSET(cset) + q;
21135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46480 times.
46480 if (get_bit(colors_used, ind))
21136 {
21137 46480 si[0] = scripting_write_pal_color(colors[ind].r);
21138 46480 si[1] = scripting_write_pal_color(colors[ind].g);
21139 46480 si[2] = scripting_write_pal_color(colors[ind].b);
21140 46480 }
21141 46480 si += 3;
21142 46480 }
21143 2905 }
21144
21145 //Writes to a main palette cset from paldata
21146 5791 void user_paldata::write_cset_main(int32_t cset)
21147 {
21148
2/2
✓ Branch 0 taken 92656 times.
✓ Branch 1 taken 5791 times.
98447 for (int32_t q = 0; q < 16; ++q)
21149 {
21150 92656 int32_t ind = CSET(cset) + q;
21151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (get_bit(colors_used, ind))
21152 {
21153 92656 RAMpal[ind] = colors[ind];
21154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (!scripting_use_8bit_colors)
21155 92656 convertRGB(RAMpal[ind]);
21156 92656 }
21157 92656 }
21158 5791 }
21159
21160
21161 //Checks a memory cset from
21162
21163
21164
21165
21166 3425 bool user_paldata::check_cset(int32_t cset, int32_t dataset)
21167 {
21168 3425 byte* si = colordata + CSET(dataset) * 3;
21169
2/2
✓ Branch 0 taken 11375 times.
✓ Branch 1 taken 520 times.
11895 for (int32_t q = 0; q < 16; ++q)
21170 {
21171 11375 int32_t ind = CSET(cset) + q;
21172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11375 times.
11375 if (get_bit(colors_used, ind))
21173 {
21174
2/2
✓ Branch 0 taken 9482 times.
✓ Branch 1 taken 1893 times.
11375 if (scripting_read_pal_color(si[0]) != colors[ind].r)
21175 1893 return true;
21176
2/2
✓ Branch 0 taken 8470 times.
✓ Branch 1 taken 1012 times.
9482 if (scripting_read_pal_color(si[1]) != colors[ind].g)
21177 1012 return true;
21178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8470 times.
8470 if (scripting_read_pal_color(si[2]) != colors[ind].b)
21179 return true;
21180 8470 }
21181 8470 si += 3;
21182 8470 }
21183 520 return false;
21184 3425 }
21185
21186 //Checks a memory cset from the main palette
21187 17154 bool user_paldata::check_cset_main(int32_t cset)
21188 {
21189
2/2
✓ Branch 0 taken 188844 times.
✓ Branch 1 taken 11363 times.
200207 for (int32_t q = 0; q < 16; ++q)
21190 {
21191 188844 int32_t ind = CSET(cset) + q;
21192
2/2
✓ Branch 0 taken 96064 times.
✓ Branch 1 taken 92780 times.
188844 if (get_bit(colors_used, ind))
21193 {
21194
2/2
✓ Branch 0 taken 88937 times.
✓ Branch 1 taken 3843 times.
92780 if (scripting_read_pal_color(RAMpal[ind].r) != colors[ind].r)
21195 3843 return true;
21196
2/2
✓ Branch 0 taken 87200 times.
✓ Branch 1 taken 1737 times.
88937 if (scripting_read_pal_color(RAMpal[ind].g) != colors[ind].g)
21197 1737 return true;
21198
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 86989 times.
87200 if (scripting_read_pal_color(RAMpal[ind].b) != colors[ind].b)
21199 211 return true;
21200 86989 }
21201 183053 }
21202 11363 return false;
21203 17154 }
21204
21205 //Mixes a color between two paldatas
21206 139696 RGB user_paldata::mix_color(RGB start, RGB end, double percent, int32_t color_space)
21207 {
21208 139696 double upper = scripting_max_color_val;
21209 139696 int32_t direction = 0;
21210
1/13
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139696 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
139696 switch (color_space)
21211 {
21212 case CSPACE_RGB:
21213 279392 return _RGB(byte(vbound(double(zc::math::Lerp(start.r, end.r, percent)), 0.0, upper)),
21214 139696 byte(vbound(double(zc::math::Lerp(start.g, end.g, percent)), 0.0, upper)),
21215 139696 byte(vbound(double(zc::math::Lerp(start.b, end.b, percent)), 0.0, upper)));
21216 case CSPACE_CMYK:
21217 {
21218 double convert_start[4];
21219 double convert_end[4];
21220 double convert_result[4];
21221 RGBTo(start, convert_start, color_space);
21222 RGBTo(end, convert_end, color_space);
21223 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21224 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21225 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21226 convert_result[3] = zc::math::Lerp(convert_start[3], convert_end[3], percent);
21227 return RGBFrom(convert_result, color_space);
21228 }
21229 case CSPACE_HSV_CW:
21230 if (color_space == CSPACE_HSV_CW)
21231 direction = 1;
21232 [[fallthrough]];
21233 case CSPACE_HSV_CCW:
21234 if (color_space == CSPACE_HSV_CCW)
21235 direction = -1;
21236 [[fallthrough]];
21237 case CSPACE_HSV:
21238 {
21239 double convert_start[3];
21240 double convert_end[3];
21241 double convert_result[3];
21242 RGBTo(start, convert_start, color_space);
21243 RGBTo(end, convert_end, color_space);
21244 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
21245 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21246 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21247 return RGBFrom(convert_result, color_space);
21248 }
21249 case CSPACE_HSL_CW:
21250 if (color_space == CSPACE_HSL_CW)
21251 direction = 1;
21252 [[fallthrough]];
21253 case CSPACE_HSL_CCW:
21254 if (color_space == CSPACE_HSL_CCW)
21255 direction = -1;
21256 [[fallthrough]];
21257 case CSPACE_HSL:
21258 {
21259 double convert_start[3];
21260 double convert_end[3];
21261 double convert_result[3];
21262 RGBTo(start, convert_start, color_space);
21263 RGBTo(end, convert_end, color_space);
21264 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
21265 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21266 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21267 return RGBFrom(convert_result, color_space);
21268 }
21269 case CSPACE_LAB:
21270 {
21271 double convert_start[3];
21272 double convert_end[3];
21273 double convert_result[3];
21274 RGBTo(start, convert_start, color_space);
21275 RGBTo(end, convert_end, color_space);
21276 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21277 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21278 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21279 return RGBFrom(convert_result, color_space);
21280 }
21281 case CSPACE_LCH_CW:
21282 if (color_space == CSPACE_LCH_CW)
21283 direction = 1;
21284 [[fallthrough]];
21285 case CSPACE_LCH_CCW:
21286 if (color_space == CSPACE_LCH_CCW)
21287 direction = -1;
21288 [[fallthrough]];
21289 case CSPACE_LCH:
21290 {
21291 double convert_start[3];
21292 double convert_end[3];
21293 double convert_result[3];
21294 RGBTo(start, convert_start, color_space);
21295 RGBTo(end, convert_end, color_space);
21296 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21297 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21298 convert_result[2] = WrapLerp(convert_start[2], convert_end[2], percent, 0.0, 360.0, direction);
21299 return RGBFrom(convert_result, color_space);
21300 }
21301 }
21302 return start;
21303 139696 }
21304
21305 void user_paldata::RGBTo(RGB c, double arr[], int32_t color_space)
21306 {
21307 //From easyrgb.com/en/math.php
21308 double upper = scripting_max_color_val;
21309 double r = vbound(c.r / upper, 0.0, 1.0);
21310 double g = vbound(c.g / upper, 0.0, 1.0);
21311 double b = vbound(c.b / upper, 0.0, 1.0);
21312 switch (color_space)
21313 {
21314 case CSPACE_CMYK:
21315 {
21316 double c = 1.0 - r;
21317 double m = 1.0 - g;
21318 double y = 1.0 - b;
21319
21320 double k = 1.0;
21321
21322 if (c < k) k = c;
21323 if (m < k) k = m;
21324 if (y < k) k = y;
21325 if (k == 1)
21326 {
21327 c = 0.0;
21328 m = 0.0;
21329 y = 0.0;
21330 }
21331 else
21332 {
21333 c = (c - k) / (1.0 - k);
21334 m = (m - k) / (1.0 - k);
21335 y = (y - k) / (1.0 - k);
21336 }
21337 arr[0] = c;
21338 arr[1] = m;
21339 arr[2] = y;
21340 arr[3] = k;
21341 break;
21342 }
21343 case CSPACE_HSV_CW:
21344 case CSPACE_HSV_CCW:
21345 case CSPACE_HSV:
21346 {
21347 double min_val = std::min(std::min(r, g), b);
21348 double max_val = std::max(std::max(r, g), b);
21349 double del_max = max_val - min_val;
21350
21351 double h = 0;
21352 double s = 0;
21353 double v = max_val;
21354
21355 if (del_max != 0) //Set chroma if not gray
21356 {
21357 s = del_max / max_val;
21358
21359 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
21360 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
21361 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
21362
21363 if (r == max_val) h = del_b - del_g;
21364 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
21365 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
21366
21367 if (h < 0) ++h;
21368 if (h > 1) --h;
21369 }
21370
21371 arr[0] = h;
21372 arr[1] = s;
21373 arr[2] = v;
21374 break;
21375 }
21376 case CSPACE_HSL_CW:
21377 case CSPACE_HSL_CCW:
21378 case CSPACE_HSL:
21379 {
21380 double min_val = std::min(std::min(r, g), b);
21381 double max_val = std::max(std::max(r, g), b);
21382 double del_max = max_val - min_val;
21383
21384 double h = 0;
21385 double s = 0;
21386 double l = (max_val + min_val) / 2.0;
21387
21388 if (del_max != 0) //Set chroma if not gray
21389 {
21390 if (l < 0.5) s = del_max / (max_val + min_val);
21391 else s = del_max / (2 - max_val - min_val);
21392
21393 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
21394 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
21395 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
21396
21397 if (r == max_val) h = del_b - del_g;
21398 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
21399 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
21400
21401 if (h < 0) ++h;
21402 if (h > 1) --h;
21403 }
21404
21405 arr[0] = h;
21406 arr[1] = s;
21407 arr[2] = l;
21408 break;
21409 }
21410 case CSPACE_LAB:
21411 {
21412 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
21413 else r /= 12.92;
21414 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
21415 else g /= 12.92;
21416 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
21417 else b /= 12.92;
21418
21419 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
21420 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
21421 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
21422
21423 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
21424 else x = (7.787 * x) + (16.0 / 116.0);
21425 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
21426 else y = (7.787 * y) + (16.0 / 116.0);
21427 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
21428 else z = (7.787 * z) + (16.0 / 116.0);
21429
21430 double CIEL = (116 * y) - 16;
21431 double CIEa = 500 * (x - y);
21432 double CIEb = 200 * (y - z);
21433
21434 arr[0] = CIEL;
21435 arr[1] = CIEa;
21436 arr[2] = CIEb;
21437 break;
21438 }
21439 case CSPACE_LCH_CW:
21440 case CSPACE_LCH_CCW:
21441 case CSPACE_LCH:
21442 {
21443 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
21444 else r /= 12.92;
21445 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
21446 else g /= 12.92;
21447 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
21448 else b /= 12.92;
21449
21450 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
21451 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
21452 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
21453
21454 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
21455 else x = (7.787 * x) + (16.0 / 116.0);
21456 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
21457 else y = (7.787 * y) + (16.0 / 116.0);
21458 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
21459 else z = (7.787 * z) + (16.0 / 116.0);
21460
21461 double CIEL = (116 * y) - 16;
21462 double CIEa = 500 * (x - y);
21463 double CIEb = 200 * (y - z);
21464
21465 double h = atan2(CIEb, CIEa);
21466 if (h > 0) h = (h / PI) * 180;
21467 else h = 360 - (abs(h) / PI) * 180;
21468
21469 double CIEC = sqrt(pow(CIEa, 2) + pow(CIEb, 2));
21470
21471 arr[0] = CIEL;
21472 arr[1] = CIEC;
21473 arr[2] = h;
21474 break;
21475 }
21476 }
21477
21478 }
21479
21480 RGB user_paldata::RGBFrom(double arr[], int32_t color_space)
21481 {
21482 double upper = scripting_max_color_val;
21483 double r = 0.0;
21484 double g = 0.0;
21485 double b = 0.0;
21486 switch (color_space)
21487 {
21488 case CSPACE_CMYK:
21489 {
21490 double c = (arr[0] * (1 - arr[3]) + arr[3]);
21491 double m = (arr[1] * (1 - arr[3]) + arr[3]);
21492 double y = (arr[2] * (1 - arr[3]) + arr[3]);
21493
21494 r = vbound((1 - c) * upper, 0.0, upper);
21495 g = vbound((1 - m) * upper, 0.0, upper);
21496 b = vbound((1 - y) * upper, 0.0, upper);
21497 return _RGB(r, g, b);
21498 break;
21499 }
21500 case CSPACE_HSV_CW:
21501 case CSPACE_HSV_CCW:
21502 case CSPACE_HSV:
21503 {
21504 double h = arr[0];
21505 double s = arr[1];
21506 double v = arr[2];
21507
21508 if (s == 0)
21509 {
21510 r = v;
21511 g = v;
21512 b = v;
21513 }
21514 else
21515 {
21516 double var_h = h * 6;
21517 if (var_h >= 6) var_h = 0;
21518 int32_t var_i = floor(var_h);
21519 double var_1 = v * (1 - s);
21520 double var_2 = v * (1 - s * (var_h - var_i));
21521 double var_3 = v * (1 - s * (1 - (var_h - var_i)));
21522
21523 switch (var_i)
21524 {
21525 case 0:
21526 r = v;
21527 g = var_3;
21528 b = var_1;
21529 break;
21530 case 1:
21531 r = var_2;
21532 g = v;
21533 b = var_1;
21534 break;
21535 case 2:
21536 r = var_1;
21537 g = v;
21538 b = var_3;
21539 break;
21540 case 3:
21541 r = var_1;
21542 g = var_2;
21543 b = v;
21544 break;
21545 case 4:
21546 r = var_3;
21547 g = var_1;
21548 b = v;
21549 break;
21550 default:
21551 r = v;
21552 g = var_1;
21553 b = var_2;
21554 }
21555 }
21556
21557 r = vbound(r * upper, 0.0, upper);
21558 g = vbound(g * upper, 0.0, upper);
21559 b = vbound(b * upper, 0.0, upper);
21560
21561 return _RGB(r, g, b);
21562 }
21563 case CSPACE_HSL_CW:
21564 case CSPACE_HSL_CCW:
21565 case CSPACE_HSL:
21566 {
21567 double h = arr[0];
21568 double s = arr[1];
21569 double l = arr[2];
21570
21571 if (s == 0)
21572 {
21573 r = l;
21574 g = l;
21575 b = l;
21576 }
21577 else
21578 {
21579 double var_1;
21580 double var_2;
21581 if (l < 0.5)var_2 = l * (1 + s);
21582 else var_2 = (l + s) - (s * l);
21583
21584 var_1 = 2 * l - var_2;
21585
21586 r = HueToRGB(var_1, var_2, h + (1.0 / 3.0));
21587 g = HueToRGB(var_1, var_2, h);
21588 b = HueToRGB(var_1, var_2, h - (1.0 / 3.0));
21589 }
21590
21591 r = vbound(r * upper, 0.0, upper);
21592 g = vbound(g * upper, 0.0, upper);
21593 b = vbound(b * upper, 0.0, upper);
21594
21595 return _RGB(r, g, b);
21596 }
21597 case CSPACE_LAB:
21598 {
21599 double CIEL = arr[0];
21600 double CIEa = arr[1];
21601 double CIEb = arr[2];
21602
21603 double var_y = (CIEL + 16) / 116.0;
21604 double var_x = CIEa / 500.0 + var_y;
21605 double var_z = var_y - CIEb / 200.0;
21606
21607 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
21608 else var_x = (var_x - 16.0 / 116.0) / 7.787;
21609 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
21610 else var_y = (var_y - 16.0 / 116.0) / 7.787;
21611 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
21612 else var_z = (var_z - 16.0 / 116.0) / 7.787;
21613
21614 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
21615 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
21616 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
21617
21618 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
21619 else r = 12.92 * r;
21620 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
21621 else g = 12.92 * g;
21622 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
21623 else b = 12.92 * b;
21624
21625 r = vbound(r * upper, 0.0, upper);
21626 g = vbound(g * upper, 0.0, upper);
21627 b = vbound(b * upper, 0.0, upper);
21628
21629 return _RGB(r, g, b);
21630 }
21631 case CSPACE_LCH_CW:
21632 case CSPACE_LCH_CCW:
21633 case CSPACE_LCH:
21634 {
21635 double CIEL = arr[0];
21636 double CIEa = cos((arr[2] * PI) / 180.0) * arr[1];
21637 double CIEb = sin((arr[2] * PI) / 180.0) * arr[1];
21638
21639 double var_y = (CIEL + 16) / 116.0;
21640 double var_x = CIEa / 500.0 + var_y;
21641 double var_z = var_y - CIEb / 200.0;
21642
21643 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
21644 else var_y = (var_y - 16.0 / 116.0) / 7.787;
21645 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
21646 else var_x = (var_x - 16.0 / 116.0) / 7.787;
21647 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
21648 else var_z = (var_z - 16.0 / 116.0) / 7.787;
21649
21650 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
21651 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
21652 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
21653
21654 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
21655 else r = 12.92 * r;
21656 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
21657 else g = 12.92 * g;
21658 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
21659 else b = 12.92 * b;
21660
21661 r = vbound(r * upper, 0.0, upper);
21662 g = vbound(g * upper, 0.0, upper);
21663 b = vbound(b * upper, 0.0, upper);
21664
21665 return _RGB(r, g, b);
21666 }
21667 }
21668 return _RGB(0, 0, 0);
21669 }
21670 double user_paldata::HueToRGB(double v1, double v2, double vH)
21671 {
21672 if (vH < 0) vH += 1;
21673 if (vH > 1) vH -= 1;
21674 if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH);
21675 if ((2 * vH) < 1) return (v2);
21676 if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2.0 / 3.0) - vH) * 6);
21677 return (v1);
21678 }
21679
21680 double user_paldata::WrapLerp(double a, double b, double t, double min, double max, int32_t direction)
21681 {
21682 double dif = abs(a - b);
21683 double range = abs(max - min);
21684
21685 switch (direction)
21686 {
21687 case 0:
21688 if (dif > range * 0.5)
21689 dif = range - dif;
21690 if (a + dif == b)
21691 direction = 1;
21692 else
21693 direction = -1;
21694 break;
21695 case 1:
21696 if (b < a)
21697 dif = range - dif;
21698 break;
21699 case -1:
21700 if (b > a)
21701 dif = range - dif;
21702 break;
21703 }
21704
21705 double ret = zc::math::Lerp(a, a + dif * direction, t);
21706
21707 if (ret <= min)
21708 ret += range;
21709 else if (ret >= max)
21710 ret -= range;
21711 return ret;
21712 }
21713
21714 //Mixes an entire palette given two paldatas
21715 5231 void user_paldata::mix(user_paldata *pal_start, user_paldata *pal_end, double percent, int32_t color_space, int32_t start_color, int32_t end_color)
21716 {
21717
2/2
✓ Branch 0 taken 184496 times.
✓ Branch 1 taken 5231 times.
189727 for (int32_t q = start_color; q < end_color; ++q)
21718 {
21719
3/4
✓ Branch 0 taken 139696 times.
✓ Branch 1 taken 44800 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 139696 times.
184496 if (get_bit(pal_start->colors_used, q) && get_bit(pal_end->colors_used, q)) {
21720 139696 RGB start = pal_start->colors[q];
21721 139696 RGB end = pal_end->colors[q];
21722 139696 colors[q] = mix_color(start, end, percent, color_space);
21723 139696 set_bit(colors_used, q, true);
21724 139696 }
21725 184496 }
21726 5231 }
21727
21728 53 void item_display_name(const bool setter)
21729 {
21730 53 int32_t ID = ri->idata;
21731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ID) >= MAXITEMS)
21732 return;
21733 53 int32_t arrayptr = get_register(sarg1);
21734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(setter)
21735 {
21736 std::string str;
21737 ArrayH::getString(arrayptr, str, 255);
21738 strcpy(itemsbuf[ID].display_name, str.c_str());
21739 }
21740 else
21741 {
21742
3/6
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53 times.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
53 if(ArrayH::setArray(arrayptr, string(itemsbuf[ID].display_name)) == SH::_Overflow)
21743 Z_scripterrlog("Array supplied to 'itemdata->GetDisplayName()' not large enough\n");
21744 }
21745 53 }
21746 void item_shown_name()
21747 {
21748 int32_t ID = ri->idata;
21749 if(unsigned(ID) >= MAXITEMS)
21750 return;
21751 int32_t arrayptr = get_register(sarg1);
21752 if(ArrayH::setArray(arrayptr, itemsbuf[ID].get_name()) == SH::_Overflow)
21753 Z_scripterrlog("Array supplied to 'itemdata->GetShownName()' not large enough\n");
21754 }
21755
21756 void FFScript::do_getDMapData_dmapname(const bool v)
21757 {
21758 int32_t ID = ri->dmapsref;
21759 int32_t arrayptr = get_register(sarg1);
21760
21761 if(BC::checkDMapID(ID) != SH::_NoError)
21762 return;
21763
21764 if(ArrayH::setArray(arrayptr, string(DMaps[ID].name)) == SH::_Overflow)
21765 Z_scripterrlog("Array supplied to 'dmapdata->GetName()' not large enough\n");
21766 }
21767
21768 void FFScript::do_setDMapData_dmapname(const bool v)
21769 {
21770 int32_t ID = ri->dmapsref;
21771 int32_t arrayptr = get_register(sarg1);
21772
21773 string filename_str;
21774
21775 if(BC::checkDMapID(ID) != SH::_NoError)
21776 return;
21777
21778
21779 ArrayH::getString(arrayptr, filename_str, 22);
21780 strncpy(DMaps[ID].name, filename_str.c_str(), 21);
21781 DMaps[ID].name[20]='\0';
21782 }
21783
21784 void FFScript::do_getDMapData_dmaptitle(const bool v)
21785 {
21786 int32_t ID = ri->dmapsref;
21787 int32_t arrayptr = get_register(sarg1);
21788
21789 if(BC::checkDMapID(ID) != SH::_NoError)
21790 return;
21791
21792 if (!get_qr(qr_OLD_DMAP_INTRO_STRINGS))
21793 {
21794 ArrayManager am(arrayptr);
21795 am.resize(DMaps[ID].title.size() + 1);
21796 }
21797 if(ArrayH::setArray(arrayptr, string(DMaps[ID].title)) == SH::_Overflow)
21798 Z_scripterrlog("Array supplied to 'dmapdata->GetTitle()' not large enough\n");
21799 }
21800
21801 void FFScript::do_setDMapData_dmaptitle(const bool v)
21802 {
21803 int32_t ID = ri->dmapsref;
21804 int32_t arrayptr = get_register(sarg1);
21805 string filename_str;
21806
21807 if(BC::checkDMapID(ID) != SH::_NoError)
21808 return;
21809
21810 if (get_qr(qr_OLD_DMAP_INTRO_STRINGS))
21811 {
21812 char namestr[21];
21813 ArrayH::getString(arrayptr, filename_str, 21);
21814 strncpy(namestr, filename_str.c_str(), 20);
21815 namestr[20] = '\0';
21816 DMaps[ID].title.assign(namestr);
21817 }
21818 else
21819 {
21820 ArrayH::getString(arrayptr, filename_str, ArrayH::getSize(arrayptr));
21821 DMaps[ID].title = filename_str;
21822 }
21823 }
21824
21825 void FFScript::do_getDMapData_dmapintro(const bool v)
21826 {
21827 int32_t ID = ri->dmapsref;
21828 int32_t arrayptr = get_register(sarg1);
21829
21830 if(BC::checkDMapID(ID) != SH::_NoError)
21831 return;
21832
21833 if(ArrayH::setArray(arrayptr, string(DMaps[ID].intro)) == SH::_Overflow)
21834 Z_scripterrlog("Array supplied to 'dmapdata->GetIntro()' not large enough\n");
21835 }
21836
21837 void FFScript::do_setDMapData_dmapintro(const bool v)
21838 {
21839 int32_t ID = ri->dmapsref;
21840 int32_t arrayptr = get_register(sarg1);
21841 string filename_str;
21842
21843 if(BC::checkDMapID(ID) != SH::_NoError)
21844 return;
21845
21846
21847 ArrayH::getString(arrayptr, filename_str, 73);
21848 strncpy(DMaps[ID].intro, filename_str.c_str(), 72);
21849 DMaps[ID].intro[72]='\0';
21850 }
21851
21852 void FFScript::do_getDMapData_music(const bool v)
21853 {
21854 int32_t ID = ri->dmapsref;
21855 int32_t arrayptr = get_register(sarg1);
21856
21857 if(BC::checkDMapID(ID) != SH::_NoError)
21858 return;
21859
21860 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
21861 Z_scripterrlog("Array supplied to 'dmapdata->GetMusic()' not large enough\n");
21862 }
21863
21864 void FFScript::do_setDMapData_music(const bool v)
21865 {
21866 int32_t ID = ri->dmapsref;
21867 int32_t arrayptr = get_register(sarg1);
21868 string filename_str;
21869
21870 if(BC::checkDMapID(ID) != SH::_NoError)
21871 return;
21872
21873
21874 ArrayH::getString(arrayptr, filename_str, 56);
21875 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
21876 DMaps[ID].tmusic[55]='\0';
21877 }
21878
21879 6365 void FFScript::do_loadnpcdata(const bool v)
21880 {
21881 6365 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21882
21883
2/4
✓ Branch 0 taken 6365 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6365 times.
6365 if ( ID < 1 || ID > (MAXGUYS-1) )
21884 {
21885 Z_scripterrlog("Invalid NPC ID passed to Game->LoadNPCData: %d\n", ID);
21886 ri->npcdataref = MAX_DWORD;
21887 }
21888
21889 6365 else ri->npcdataref = ID;
21890 6365 }
21891 24 void FFScript::do_loadmessagedata(const bool v)
21892 {
21893 24 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21894
21895
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if ( ID < 1 || ID > (msg_count-1) )
21896 {
21897 Z_scripterrlog("Invalid Message ID passed to Game->LoadMessageData: %d\n", ID);
21898 ri->zmsgref = MAX_DWORD;
21899 }
21900
21901 24 else ri->zmsgref = ID;
21902 24 }
21903 //same syntax as loadmessage data
21904 //the input is an array
21905 24 void FFScript::do_messagedata_setstring(const bool v)
21906 {
21907 24 int32_t arrayptr = get_register(sarg1);
21908 24 int32_t ID = ri->zmsgref;
21909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
21910 return;
21911
21912 24 std::string s;
21913
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ArrayH::getString(arrayptr, s, MSG_NEW_SIZE);
21914
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 MsgStrings[ID].setFromLegacyEncoding(s);
21915 24 }
21916 void FFScript::do_messagedata_getstring(const bool v)
21917 {
21918 int32_t ID = ri->zmsgref;
21919 int32_t arrayptr = get_register(sarg1);
21920
21921 if(BC::checkMessage(ID) != SH::_NoError)
21922 return;
21923
21924 if(ArrayH::setArray(arrayptr, MsgStrings[ID].s) == SH::_Overflow)
21925 Z_scripterrlog("Array supplied to 'messagedata->Get()' not large enough\n");
21926 }
21927
21928 432438 void FFScript::do_loadcombodata(const bool v)
21929 {
21930 432438 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21931
21932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 432438 times.
432438 if ( (unsigned)ID > (MAXCOMBOS-1) )
21933 {
21934 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
21935 ri->combosref = 0;
21936 }
21937
21938 432438 else ri->combosref = ID;
21939 432438 }
21940
21941 3209679 void FFScript::do_loadmapdata_tempscr(const bool v)
21942 {
21943 3209679 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21944
21945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3209679 times.
3209679 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21946 {
21947 ri->mapsref = 0;
21948 set_register(sarg1, ri->mapsref);
21949 return;
21950 }
21951
21952 3209679 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentRegion, cur_screen, layer);
21953 3209679 set_register(sarg1, ri->mapsref);
21954 3209679 }
21955
21956 void FFScript::do_loadmapdata_tempscr2(const bool v)
21957 {
21958 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21959 int32_t screen = SH::get_arg(sarg2, v) / 10000;
21960
21961 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21962 {
21963 ri->mapsref = 0;
21964 set_register(sarg1, ri->mapsref);
21965 return;
21966 }
21967
21968 if (!is_in_current_region(screen))
21969 {
21970 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
21971 ri->mapsref = 0;
21972 set_register(sarg1, ri->mapsref);
21973 return;
21974 }
21975
21976 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, screen, layer);
21977 set_register(sarg1, ri->mapsref);
21978 }
21979
21980 static void do_loadtmpscrforcombopos(const bool v)
21981 {
21982 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21983 rpos_t rpos = (rpos_t)(SH::get_arg(sarg2, v) / 10000);
21984
21985 if (BC::checkBoundsRpos(rpos, (rpos_t)0, region_max_rpos) != SH::_NoError)
21986 {
21987 ri->mapsref = 0;
21988 set_register(sarg1, ri->mapsref);
21989 return;
21990 }
21991 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21992 {
21993 ri->mapsref = 0;
21994 set_register(sarg1, ri->mapsref);
21995 return;
21996 }
21997
21998 set_register(sarg1, create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, get_screen_for_rpos(rpos), layer));
21999 }
22000
22001 177544 void FFScript::do_loadmapdata_scrollscr(const bool v)
22002 {
22003 177544 int32_t layer = SH::get_arg(sarg1, v) / 10000;
22004
22005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 177544 times.
177544 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
22006 {
22007 ri->mapsref = 0;
22008 set_register(sarg1, ri->mapsref);
22009 return;
22010 }
22011
22012 177544 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingRegion, scrolling_hero_screen, layer);
22013 177544 set_register(sarg1, ri->mapsref);
22014 177544 }
22015
22016 void FFScript::do_loadmapdata_scrollscr2(const bool v)
22017 {
22018 int32_t layer = SH::get_arg(sarg1, v) / 10000;
22019 int32_t screen = SH::get_arg(sarg2, v) / 10000;
22020
22021 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
22022 {
22023 ri->mapsref = 0;
22024 set_register(sarg1, ri->mapsref);
22025 return;
22026 }
22027
22028 if (!is_in_scrolling_region(screen))
22029 {
22030 scripting_log_error_with_context("Must use a screen in the current scrolling region. got: {}", screen);
22031 ri->mapsref = 0;
22032 set_register(sarg1, ri->mapsref);
22033 return;
22034 }
22035
22036 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingScreen, screen, layer);
22037 set_register(sarg1, ri->mapsref);
22038 }
22039
22040 void FFScript::do_loadshopdata(const bool v)
22041 {
22042 int32_t ID = SH::get_arg(sarg1, v) / 10000;
22043
22044 if ( (unsigned)ID > 255 )
22045 {
22046 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
22047 ri->shopsref = 0;
22048 }
22049 else ri->shopsref = ID;
22050 }
22051
22052
22053 void FFScript::do_loadinfoshopdata(const bool v)
22054 {
22055 int32_t ID = SH::get_arg(sarg1, v) / 10000;
22056
22057 if ( (unsigned)ID > 255 )
22058 {
22059 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
22060 ri->shopsref = 0;
22061 }
22062 else ri->shopsref = ID+NUMSHOPS;
22063 }
22064
22065 16 void FFScript::do_loadspritedata(const bool v)
22066 {
22067 16 int32_t ID = SH::get_arg(sarg1, v) / 10000;
22068
22069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if ( (unsigned)ID > (MAXWPNS-1) )
22070 {
22071 Z_scripterrlog("Invalid Sprite ID passed to Game->LoadSpriteData: %d\n", ID);
22072 ri->spritedataref = 0;
22073 }
22074
22075 16 else ri->spritedataref = ID;
22076 16 }
22077
22078 10 void FFScript::do_loadbitmapid(const bool v)
22079 {
22080 10 int32_t ID = SH::get_arg(sarg1, v) / 10000;
22081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 switch(ID)
22082 {
22083 case rtSCREEN:
22084 case rtBMP0:
22085 case rtBMP1:
22086 case rtBMP2:
22087 case rtBMP3:
22088 case rtBMP4:
22089 case rtBMP5:
22090 case rtBMP6:
22091 10 ri->bitmapref = ID+10; break;
22092 default:
22093 {
22094 Z_scripterrlog("Invalid Bitmap ID passed to Game->Load BitmapID: %d\n", ID);
22095 ri->bitmapref = 0; break;
22096 }
22097 }
22098 10 }
22099
22100 87669 void do_createlweapon(const bool v)
22101 {
22102 87669 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22103
22104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87669 times.
87669 if(BC::checkWeaponID(ID) != SH::_NoError)
22105 return;
22106
22107
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 if ( Lwpns.has_space() )
22108 {
22109 87669 (void)Lwpns.add
22110 (
22111
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
175338 new weapon
22112 (
22113
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*X*/
22114
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*Y*/
22115
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*Z*/
22116 87669 ID, /*id*/
22117 0, /*type*/
22118 0, /*power*/
22119 0, /*dir*/
22120 -1, /*Parentid*/
22121
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 Hero.getUID(), /*prntid*/
22122 false, /*isdummy*/
22123 1, /*script_gen*/
22124 1, /*islwpn*/
22125 87669 (ID==wWind?1:0) /*special*/
22126 )
22127 );
22128 87669 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
22129 87669 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
22130 87669 w->screen_spawned = ri->screenref;
22131 87669 w->ScriptGenerated = 1;
22132 87669 w->isLWeapon = 1;
22133
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 if(ID == wWind) w->specialinfo = 1;
22134 87669 Z_eventlog("Script created lweapon %d with UID = %u\n", ID, ri->lwpn);
22135 87669 }
22136 else
22137 {
22138 ri->lwpn = 0; // Now NULL
22139 Z_scripterrlog("Couldn't create lweapon %d, screen lweapon limit reached\n", ID);
22140 }
22141 87669 }
22142
22143 209493 void do_createeweapon(const bool v)
22144 {
22145 209493 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22146
22147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209493 times.
209493 if(BC::checkWeaponID(ID) != SH::_NoError)
22148 return;
22149
22150
1/2
✓ Branch 0 taken 209493 times.
✗ Branch 1 not taken.
209493 if ( Ewpns.has_space() )
22151 {
22152 209493 addEwpn(0, 0, 0, ID, 0, 0, 0, -1,1); //Param 9 marks it as script-generated.
22153
4/6
✓ Branch 0 taken 150748 times.
✓ Branch 1 taken 58745 times.
✓ Branch 2 taken 150748 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150748 times.
✗ Branch 5 not taken.
209493 if( ID > wEnemyWeapons || ( ID >= wScript1 && ID <= wScript10) )
22154 {
22155 209493 weapon *w = (weapon*)Ewpns.spr(Ewpns.Count()-1); //last created
22156 209493 w->screen_spawned = ri->screenref;
22157 209493 w->ScriptGenerated = 1;
22158 209493 w->isLWeapon = 0;
22159 209493 ri->ewpn = Ewpns.spr(Ewpns.Count() - 1)->getUID();
22160 209493 Z_eventlog("Script created eweapon %d with UID = %u\n", ID, ri->ewpn);
22161 209493 }
22162 else
22163 {
22164 Z_scripterrlog("Couldn't create eweapon: Invalid ID/Type (%d) specified.\n", ID);
22165 return;
22166 }
22167 209493 }
22168 else
22169 {
22170 ri->ewpn = 0;
22171 Z_scripterrlog("Couldn't create eweapon %d, screen eweapon limit reached\n", ID);
22172 }
22173 209493 }
22174
22175 22444 void do_createitem(const bool v)
22176 {
22177 22444 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22178
22179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22444 times.
22444 if(BC::checkItemID(ID) != SH::_NoError)
22180 return;
22181
22182
1/2
✓ Branch 0 taken 22444 times.
✗ Branch 1 not taken.
22444 if ( items.has_space() )
22183 {
22184 22444 additem(0, (get_qr(qr_NOITEMOFFSET) ? 1: 0), ID, ipBIGRANGE);
22185 22444 sprite* item = items.spr(items.Count() - 1);
22186 22444 item->screen_spawned = ri->screenref;
22187 22444 ri->itemref = item->getUID();
22188 22444 Z_eventlog("Script created item \"%s\" with UID = %u\n", item_string[ID], ri->itemref);
22189 22444 }
22190 else
22191 {
22192 ri->itemref = 0;
22193 Z_scripterrlog("Couldn't create item \"%s\", screen item limit reached\n", item_string[ID]);
22194 }
22195 22444 }
22196
22197 3530 void do_createnpc(const bool v)
22198 {
22199 3530 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22200
22201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(BC::checkGuyID(ID) != SH::_NoError)
22202 return;
22203
22204 //If we make a segmented enemy there'll be more than one sprite created
22205 3530 word numcreated = addenemy(ri->screenref, 0, 0, ID, -10);
22206
22207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(numcreated == 0)
22208 {
22209 //ri->guyref = MAX_DWORD;
22210 ri->guyref = 0;
22211 Z_scripterrlog("Couldn't create NPC \"%s\", screen NPC limit reached\n", guy_string[ID]);
22212 }
22213 else
22214 {
22215 3530 word index = guys.Count() - numcreated; //Get the main enemy, not a segment
22216 3530 ri->guyref = guys.spr(index)->getUID();
22217
22218
2/2
✓ Branch 0 taken 3566 times.
✓ Branch 1 taken 3530 times.
7096 for(; index<guys.Count(); index++)
22219 3566 ((enemy*)guys.spr(index))->script_spawned=true;
22220
22221 3530 Z_eventlog("Script created NPC \"%s\" with UID = %u\n", guy_string[ID], ri->guyref);
22222 }
22223 3530 }
22224
22225 ///----------------------------------------------------------------------------------------------------//
22226 //Drawing & Sound
22227
22228 1117 void do_message(const bool v)
22229 {
22230 1117 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22231
22232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1117 times.
1117 if(BC::checkMessage(ID) != SH::_NoError)
22233 return;
22234
22235
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 815 times.
1117 if(ID == 0)
22236 {
22237 302 dismissmsg();
22238 302 msgfont = get_zc_font(font_zfont);
22239 302 blockpath = false;
22240 302 Hero.finishedmsg();
22241 302 }
22242 else
22243 815 donewmsg(get_scr(ri->screenref), ID);
22244 1117 }
22245
22246 45275697 INLINE void set_drawing_command_args(const int32_t j, const word numargs)
22247 {
22248
1/2
✓ Branch 0 taken 45275697 times.
✗ Branch 1 not taken.
45275697 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
22249
2/2
✓ Branch 0 taken 368858393 times.
✓ Branch 1 taken 45275697 times.
414134090 for(int32_t k = 1; k <= numargs; k++)
22250 368858393 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
22251 45275697 }
22252
22253 53711106 INLINE void set_user_bitmap_command_args(const int32_t j, const word numargs)
22254 {
22255
1/2
✓ Branch 0 taken 53711106 times.
✗ Branch 1 not taken.
53711106 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
22256 //ri->bitmapref = SH::read_stack(ri->sp+numargs);
22257
2/2
✓ Branch 0 taken 326059206 times.
✓ Branch 1 taken 53711106 times.
379770312 for(int32_t k = 1; k <= numargs; k++)
22258 326059206 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
22259 53711106 }
22260
22261 98985723 static DrawOrigin get_draw_origin_for_screen_draw_command()
22262 {
22263 98985723 DrawOrigin draw_origin = ri->screen_draw_origin;
22264
22265
2/2
✓ Branch 0 taken 121364 times.
✓ Branch 1 taken 98864359 times.
98985723 if (draw_origin == DrawOrigin::Default)
22266 {
22267
4/4
✓ Branch 0 taken 8256 times.
✓ Branch 1 taken 98856103 times.
✓ Branch 2 taken 94944008 times.
✓ Branch 3 taken 3912095 times.
98864359 bool in_scrolling_region = is_in_scrolling_region() || (screenscrolling && scrolling_region.screen_count > 1);
22268 98864359 draw_origin = in_scrolling_region ? DrawOrigin::Region : DrawOrigin::PlayingField;
22269 98864359 }
22270
2/2
✓ Branch 0 taken 46076 times.
✓ Branch 1 taken 98939647 times.
98985723 if (draw_origin == DrawOrigin::Region)
22271 {
22272
2/2
✓ Branch 0 taken 38992 times.
✓ Branch 1 taken 7084 times.
46076 if (scrolling_using_new_region_coords)
22273 7084 draw_origin = DrawOrigin::RegionScrollingNew;
22274 46076 }
22275
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 98938163 times.
98939647 else if (draw_origin == DrawOrigin::RegionScrollingOld)
22276 {
22277 1484 draw_origin = DrawOrigin::Region;
22278 1484 }
22279
2/2
✓ Branch 0 taken 98937175 times.
✓ Branch 1 taken 988 times.
98938163 else if (draw_origin == DrawOrigin::RegionScrollingNew)
22280 {
22281
1/2
✓ Branch 0 taken 988 times.
✗ Branch 1 not taken.
988 if (!screenscrolling)
22282 draw_origin = DrawOrigin::Region;
22283 988 }
22284
22285 98985723 return draw_origin;
22286 }
22287
22288 1440 static DrawOrigin get_draw_origin_for_bitmap_draw_command()
22289 {
22290 1440 return DrawOrigin::Screen;
22291 }
22292
22293 98987163 static std::pair<DrawOrigin, int> get_draw_origin_for_draw_command(bool is_screen_draw, int scripting_bitmap_id)
22294 {
22295
2/2
✓ Branch 0 taken 98985363 times.
✓ Branch 1 taken 1800 times.
98987163 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22296 98985363 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
22297
22298 1800 auto [bitmap_id, _] = resolveScriptingBitmapId(scripting_bitmap_id);
22299
22300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 if (FFCore.doesResolveToDeprecatedSystemBitmap(bitmap_id))
22301 return {DrawOrigin::Screen, 0};
22302
22303
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 1440 times.
1800 if (FFCore.doesResolveToScreenBitmap(bitmap_id))
22304 360 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
22305
22306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (!is_screen_draw)
22307 1440 return {get_draw_origin_for_bitmap_draw_command(), 0};
22308
22309 return {DrawOrigin::Screen, 0};
22310 98987163 }
22311
22312 98986803 static void do_drawing_command(int32_t script_command, bool is_screen_draw)
22313 {
22314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98986803 times.
98986803 if (FFCore.skipscriptdraws)
22315 return;
22316
22317 98986803 int32_t j = script_drawing_commands.GetNext();
22318
1/2
✓ Branch 0 taken 98986803 times.
✗ Branch 1 not taken.
98986803 if(j == -1) //out of drawing command space
22319 {
22320 Z_scripterrlog("Max draw primitive limit reached\n");
22321 return;
22322 }
22323
22324 98986803 script_drawing_commands[j] = {};
22325 98986803 script_drawing_commands[j][0] = script_command;
22326 98986803 script_drawing_commands[j][DRAWCMD_CURRENT_TARGET] = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
22327
22328
39/81
✓ Branch 0 taken 2428096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1096118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 383247 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2698101 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 900326 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 49606 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 321769 times.
✓ Branch 13 taken 3150 times.
✓ Branch 14 taken 26528 times.
✓ Branch 15 taken 148823 times.
✓ Branch 16 taken 144 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 824 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 167318 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1173 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 19821648 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 906 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 2051 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 7323 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1850 times.
✓ Branch 40 taken 2356839 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 1080 times.
✓ Branch 46 taken 1527166 times.
✓ Branch 47 taken 5152881 times.
✓ Branch 48 taken 21691969 times.
✓ Branch 49 taken 963845 times.
✓ Branch 50 taken 148476 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 9270 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 4137125 times.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1568537 times.
✓ Branch 58 taken 161165 times.
✓ Branch 59 taken 7971 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 502 times.
✓ Branch 65 taken 80910 times.
✓ Branch 66 taken 59561 times.
✓ Branch 67 taken 32636464 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 865 times.
✓ Branch 70 taken 45504 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 264343 times.
✓ Branch 75 taken 113329 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
98986803 switch(script_command)
22329 {
22330 case RECTR:
22331 2428096 set_drawing_command_args(j, 12);
22332 2428096 break;
22333
22334 case FRAMER:
22335 set_drawing_command_args(j, 9);
22336 break;
22337
22338 case CIRCLER:
22339 1096118 set_drawing_command_args(j, 11);
22340 1096118 break;
22341
22342 case ARCR:
22343 set_drawing_command_args(j, 14);
22344 break;
22345
22346 case ELLIPSER:
22347 1850 set_drawing_command_args(j, 12);
22348 1850 break;
22349
22350 case LINER:
22351 2356839 set_drawing_command_args(j, 11);
22352 2356839 break;
22353
22354 case PUTPIXELR:
22355 383247 set_drawing_command_args(j, 8);
22356 383247 break;
22357
22358 case PIXELARRAYR:
22359 {
22360 set_drawing_command_args(j, 5);
22361 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22362
22363 int32_t arrayptr = script_drawing_commands[j][2];
22364 if ( !arrayptr ) //Don't crash because of vector size.
22365 {
22366 Z_scripterrlog("Invalid array pointer %d passed to Screen->PutPixels(). Aborting.", arrayptr);
22367 break;
22368 }
22369 int32_t sz = ArrayH::getSize(arrayptr);
22370 if(!sz)
22371 {
22372 script_drawing_commands.PopLast();
22373 return;
22374 }
22375 v->resize(sz, 0);
22376 int32_t* pos = &v->at(0);
22377
22378 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22379 script_drawing_commands[j].SetVector(v);
22380 break;
22381 }
22382
22383 case TILEARRAYR:
22384 {
22385 set_drawing_command_args(j, 2);
22386 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22387
22388 int32_t arrayptr = script_drawing_commands[j][2];
22389 if ( !arrayptr ) //Don't crash because of vector size.
22390 {
22391 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawTiles(). Aborting.", arrayptr);
22392 break;
22393 }
22394 int32_t sz = ArrayH::getSize(arrayptr);
22395 if(!sz)
22396 {
22397 script_drawing_commands.PopLast();
22398 return;
22399 }
22400 v->resize(sz, 0);
22401 int32_t* pos = &v->at(0);
22402
22403 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22404 script_drawing_commands[j].SetVector(v);
22405 break;
22406 }
22407
22408 case LINESARRAY:
22409 {
22410 set_drawing_command_args(j, 2);
22411 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22412
22413 int32_t arrayptr = script_drawing_commands[j][2];
22414 if ( !arrayptr ) //Don't crash because of vector size.
22415 {
22416 Z_scripterrlog("Invalid array pointer %d passed to Screen->Lines(). Aborting.", arrayptr);
22417 break;
22418 }
22419 int32_t sz = ArrayH::getSize(arrayptr);
22420 if(!sz)
22421 {
22422 script_drawing_commands.PopLast();
22423 return;
22424 }
22425 v->resize(sz, 0);
22426 int32_t* pos = &v->at(0);
22427
22428 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22429 script_drawing_commands[j].SetVector(v);
22430 break;
22431 }
22432
22433 case COMBOARRAYR:
22434 {
22435 set_drawing_command_args(j, 2);
22436 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22437 int32_t arrayptr = script_drawing_commands[j][2];
22438 if ( !arrayptr ) //Don't crash because of vector size.
22439 {
22440 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawCombos(). Aborting.", arrayptr);
22441 break;
22442 }
22443 int32_t sz = ArrayH::getSize(arrayptr);
22444 if(!sz)
22445 {
22446 script_drawing_commands.PopLast();
22447 return;
22448 }
22449 v->resize(sz, 0);
22450 int32_t* pos = &v->at(0);
22451
22452 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22453 script_drawing_commands[j].SetVector(v);
22454 break;
22455 }
22456 case POLYGONR:
22457 {
22458 1080 set_drawing_command_args(j, 5);
22459
22460 1080 int32_t arrayptr = script_drawing_commands[j][3];
22461
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if ( !arrayptr ) //Don't crash because of vector size.
22462 {
22463 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
22464 break;
22465 }
22466 1080 int32_t sz = ArrayH::getSize(arrayptr);
22467
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!sz)
22468 {
22469 script_drawing_commands.PopLast();
22470 return;
22471 }
22472
22473 1080 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22474 1080 v->resize(sz, 0);
22475
22476 1080 int32_t* pos = &v->at(0);
22477
22478
22479 1080 ArrayH::getValues(script_drawing_commands[j][3], pos, sz);
22480 1080 script_drawing_commands[j].SetVector(v);
22481 }
22482 1080 break;
22483
22484 case DRAWTILER:
22485 1527166 set_drawing_command_args(j, 15);
22486 1527166 break;
22487
22488 case DRAWTILECLOAKEDR:
22489 set_drawing_command_args(j, 7);
22490 break;
22491
22492 case DRAWCOMBOR:
22493 2698101 set_drawing_command_args(j, 16);
22494 2698101 break;
22495
22496 case DRAWCOMBOCLOAKEDR:
22497 set_drawing_command_args(j, 7);
22498 break;
22499
22500 case FASTTILER:
22501 5152881 set_drawing_command_args(j, 6);
22502 5152881 break;
22503
22504 case FASTCOMBOR:
22505 21691969 set_drawing_command_args(j, 6);
22506 21691969 break;
22507
22508 case DRAWCHARR:
22509 963845 set_drawing_command_args(j, 10);
22510 963845 break;
22511
22512 case DRAWINTR:
22513 148476 set_drawing_command_args(j, 11);
22514 148476 break;
22515
22516 case SPLINER:
22517 set_drawing_command_args(j, 11);
22518 break;
22519
22520 case QUADR:
22521 9270 set_drawing_command_args(j, 15);
22522 9270 break;
22523
22524 case TRIANGLER:
22525 set_drawing_command_args(j, 13);
22526 break;
22527
22528 case BITMAPR:
22529 900326 set_drawing_command_args(j, 12);
22530 900326 break;
22531
22532 case BITMAPEXR:
22533 set_drawing_command_args(j, 16);
22534 break;
22535
22536 case DRAWLAYERR:
22537 4137125 set_drawing_command_args(j, 8);
22538 4137125 break;
22539
22540 case DRAWSCREENR:
22541 49606 set_drawing_command_args(j, 6);
22542 49606 break;
22543
22544 case QUAD3DR:
22545 {
22546 set_drawing_command_args(j, 8);
22547 int32_t arrayptr = script_drawing_commands[j][2];
22548 int32_t sz = ArrayH::getSize(arrayptr);
22549 arrayptr = script_drawing_commands[j][3];
22550 sz += ArrayH::getSize(arrayptr);
22551 arrayptr = script_drawing_commands[j][4];
22552 sz += ArrayH::getSize(arrayptr);
22553 arrayptr = script_drawing_commands[j][5];
22554 sz += ArrayH::getSize(arrayptr);
22555 if(sz < 25)
22556 {
22557 script_drawing_commands.PopLast();
22558 return;
22559 }
22560 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22561 v->resize(sz, 0);
22562
22563 int32_t* pos = &v->at(0);
22564 int32_t* uv = &v->at(12);
22565 int32_t* col = &v->at(20);
22566 int32_t* size = &v->at(24);
22567
22568 ArrayH::getValues((script_drawing_commands[j][2]), pos, 12);
22569 ArrayH::getValues((script_drawing_commands[j][3]), uv, 8);
22570 ArrayH::getValues((script_drawing_commands[j][4]), col, 4);
22571 //FFCore.getValues2(script_drawing_commands[j][5], size, 2);
22572 ArrayH::getValues((script_drawing_commands[j][5]), size, 2);
22573
22574 script_drawing_commands[j].SetVector(v);
22575 }
22576 break;
22577
22578 case TRIANGLE3DR:
22579 {
22580 set_drawing_command_args(j, 8);
22581
22582 int32_t arrayptr = script_drawing_commands[j][2];
22583 int32_t sz = ArrayH::getSize(arrayptr);
22584 arrayptr = script_drawing_commands[j][3];
22585 sz += ArrayH::getSize(arrayptr);
22586 arrayptr = script_drawing_commands[j][4];
22587 sz += ArrayH::getSize(arrayptr);
22588 arrayptr = script_drawing_commands[j][5];
22589 sz += ArrayH::getSize(arrayptr);
22590 if(sz < 19)
22591 {
22592 script_drawing_commands.PopLast();
22593 return;
22594 }
22595
22596 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22597 v->resize(sz, 0);
22598
22599 int32_t* pos = &v->at(0);
22600 int32_t* uv = &v->at(9);
22601 int32_t* col = &v->at(15);
22602 int32_t* size = &v->at(18);
22603
22604 ArrayH::getValues(script_drawing_commands[j][2], pos, 8);
22605 ArrayH::getValues(script_drawing_commands[j][3], uv, 6);
22606 ArrayH::getValues(script_drawing_commands[j][4], col, 3);
22607 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22608
22609 script_drawing_commands[j].SetVector(v);
22610 }
22611 break;
22612
22613 case DRAWSTRINGR:
22614 {
22615 1568537 set_drawing_command_args(j, 9);
22616 // Unused
22617 //const int32_t index = script_drawing_commands[j][19] = j;
22618
22619 1568537 string *str = script_drawing_commands.GetString();
22620 1568537 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22621 1568537 script_drawing_commands[j].SetString(str);
22622 }
22623 1568537 break;
22624
22625 case DRAWSTRINGR2:
22626 {
22627 161165 set_drawing_command_args(j, 11);
22628 // Unused
22629 //const int32_t index = script_drawing_commands[j][19] = j;
22630
22631 161165 string *str = script_drawing_commands.GetString();
22632 161165 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22633 161165 script_drawing_commands[j].SetString(str);
22634 }
22635 161165 break;
22636
22637 case BMPRECTR:
22638 7971 set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12);
22639 //Pop the args off the stack first. Then pop the pointer and push it to sdci[17].
22640 //The pointer for the bitmap variable (its literal value) is always ri->sp+numargs, so, with 12 args, it is sp+12.
22641 7971 break;
22642
22643 case BMPFRAMER:
22644 set_user_bitmap_command_args(j, 9);
22645 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22646 break;
22647
22648 case CLEARBITMAP:
22649 {
22650 321769 set_user_bitmap_command_args(j, 1);
22651 321769 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+1);
22652 321769 break;
22653 }
22654 case BITMAPCLEARTOCOLOR:
22655 {
22656 3150 set_user_bitmap_command_args(j, 2);
22657 3150 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
22658 3150 break;
22659 }
22660 case REGENERATEBITMAP:
22661 {
22662 26528 set_user_bitmap_command_args(j, 3);
22663 26528 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22664 26528 break;
22665 }
22666 case BMPPOLYGONR:
22667 {
22668 set_user_bitmap_command_args(j, 5);
22669 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22670 int32_t arrayptr = script_drawing_commands[j][3];
22671 if ( !arrayptr ) //Don't crash because of vector size.
22672 {
22673 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
22674 break;
22675 }
22676 int32_t sz = ArrayH::getSize(arrayptr);
22677 if(!sz)
22678 {
22679 script_drawing_commands.PopLast();
22680 return;
22681 }
22682 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22683 v->resize(sz, 0);
22684
22685 int32_t* pos = &v->at(0);
22686
22687
22688 ArrayH::getValues(script_drawing_commands[j][3], pos, sz);
22689 script_drawing_commands[j].SetVector(v);
22690 }
22691 break;
22692 case READBITMAP:
22693 {
22694 set_user_bitmap_command_args(j, 2);
22695 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
22696 string& user_path = *script_drawing_commands.GetString();
22697 ArrayH::getString(script_drawing_commands[j][2], user_path, 256);
22698
22699 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
22700 {
22701 if (auto r = parse_user_path(user_path, true); !r)
22702 {
22703 scripting_log_error_with_context("Error: {}", r.error());
22704 return;
22705 } else user_path = r.value();
22706 }
22707 else
22708 {
22709 regulate_path(user_path);
22710 }
22711
22712 script_drawing_commands[j].SetString(&user_path);
22713 break;
22714 }
22715 case WRITEBITMAP:
22716 {
22717 set_user_bitmap_command_args(j, 3);
22718 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22719 std::string& user_path = *script_drawing_commands.GetString();
22720 ArrayH::getString(script_drawing_commands[j][2], user_path, 256);
22721
22722 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
22723 {
22724 if (auto r = parse_user_path(user_path, true); !r)
22725 {
22726 scripting_log_error_with_context("Error: {}", r.error());
22727 return;
22728 } else user_path = r.value();
22729 }
22730 else
22731 {
22732 regulate_path(user_path);
22733 }
22734
22735 script_drawing_commands[j].SetString(&user_path);
22736 break;
22737 }
22738
22739 148823 case BMPCIRCLER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22740 case BMPARCR: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
22741 502 case BMPELLIPSER: set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12); break;
22742 144 case BMPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22743 case BMPSPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22744 80910 case BMPPUTPIXELR: set_user_bitmap_command_args(j, 8); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8); break;
22745 59561 case BMPDRAWTILER: set_user_bitmap_command_args(j, 15); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+15); break;
22746 case BMPDRAWTILECLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
22747 824 case BMPDRAWCOMBOR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
22748 case BMPDRAWCOMBOCLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
22749 167318 case BMPFASTTILER: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22750 32636464 case BMPFASTCOMBOR: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22751 case BMPDRAWCHARR: set_user_bitmap_command_args(j, 10); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+10); break;
22752 case BMPDRAWINTR: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22753 case BMPDRAWSTRINGR:
22754 {
22755 865 set_user_bitmap_command_args(j, 9);
22756 865 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22757 // Unused
22758 //const int32_t index = script_drawing_commands[j][19] = j;
22759
22760 865 string *str = script_drawing_commands.GetString();
22761 865 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22762 865 script_drawing_commands[j].SetString(str);
22763
22764 }
22765 865 break;
22766 case BMPDRAWSTRINGR2:
22767 {
22768 45504 set_user_bitmap_command_args(j, 11);
22769 45504 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11);
22770 // Unused
22771 //const int32_t index = script_drawing_commands[j][19] = j;
22772
22773 45504 string *str = script_drawing_commands.GetString();
22774 45504 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22775 45504 script_drawing_commands[j].SetString(str);
22776
22777 }
22778 45504 break;
22779 case BMPQUADR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
22780 case BMPQUAD3DR:
22781 {
22782 set_drawing_command_args(j, 9);
22783 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22784 v->resize(26, 0);
22785
22786 int32_t* pos = &v->at(0);
22787 int32_t* uv = &v->at(12);
22788 int32_t* col = &v->at(20);
22789 int32_t* size = &v->at(24);
22790
22791
22792 ArrayH::getValues(script_drawing_commands[j][2], pos, 12);
22793 ArrayH::getValues(script_drawing_commands[j][3], uv, 8);
22794 ArrayH::getValues(script_drawing_commands[j][4], col, 4);
22795 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22796
22797 script_drawing_commands[j].SetVector(v);
22798 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22799
22800 }
22801 break;
22802 case BMPTRIANGLER: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
22803 case BMPTRIANGLE3DR:
22804 {
22805 set_drawing_command_args(j, 9);
22806
22807 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22808 v->resize(20, 0);
22809
22810 int32_t* pos = &v->at(0);
22811 int32_t* uv = &v->at(9);
22812 int32_t* col = &v->at(15);
22813 int32_t* size = &v->at(18);
22814
22815
22816 ArrayH::getValues(script_drawing_commands[j][2], pos, 8);
22817 ArrayH::getValues(script_drawing_commands[j][3], uv, 6);
22818 ArrayH::getValues(script_drawing_commands[j][4], col, 3);
22819 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22820
22821 script_drawing_commands[j].SetVector(v);
22822 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22823 break;
22824 }
22825
22826 case BMPDRAWLAYERR:
22827 1173 set_user_bitmap_command_args(j, 8);
22828 1173 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8);
22829 1173 break;
22830 case BMPDRAWLAYERSOLIDR:
22831 case BMPDRAWLAYERCFLAGR:
22832 case BMPDRAWLAYERCTYPER:
22833 case BMPDRAWLAYERCIFLAGR:
22834 case BMPDRAWLAYERSOLIDITYR: set_user_bitmap_command_args(j, 9); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9); break;
22835 case BMPDRAWSCREENR:
22836 case BMPDRAWSCREENSOLIDR:
22837 case BMPDRAWSCREENSOLID2R:
22838 case BMPDRAWSCREENCOMBOFR:
22839 case BMPDRAWSCREENCOMBOIR:
22840 case BMPDRAWSCREENCOMBOTR:
22841 2051 set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22842 case BITMAPGETPIXEL:
22843 {
22844 set_user_bitmap_command_args(j, 3); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22845 break;
22846 }
22847 case BMPBLIT:
22848 {
22849 264343 set_user_bitmap_command_args(j, 16);
22850
22851 264343 int bmp_target = SH::read_stack(ri->sp+16);
22852 264343 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = bmp_target;
22853
22854
2/2
✓ Branch 0 taken 263983 times.
✓ Branch 1 taken 360 times.
264343 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22855 {
22856 360 int bmp_dest = script_drawing_commands[j][2];
22857 720 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_dest);
22858 360 script_drawing_commands[j].secondary_draw_origin = draw_origin;
22859 360 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
22860 360 }
22861 264343 break;
22862 }
22863 case BMPBLITTO:
22864 {
22865 113329 set_user_bitmap_command_args(j, 16);
22866 113329 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16);
22867
22868
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22869 {
22870 int bmp_source = script_drawing_commands[j][2];
22871 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_source);
22872 script_drawing_commands[j].secondary_draw_origin = draw_origin;
22873 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
22874 }
22875 113329 break;
22876 }
22877 case TILEBLIT:
22878 {
22879 set_drawing_command_args(j, 17);
22880 break;
22881 }
22882 case COMBOBLIT:
22883 {
22884 set_drawing_command_args(j, 17);
22885 break;
22886 }
22887 case BMPTILEBLIT:
22888 {
22889 set_user_bitmap_command_args(j, 17);
22890 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
22891 break;
22892 }
22893 case BMPCOMBOBLIT:
22894 {
22895 set_user_bitmap_command_args(j, 17);
22896 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
22897 break;
22898 }
22899 case BMPMODE7:
22900 {
22901 set_user_bitmap_command_args(j, 13);
22902 //for(int32_t q = 0; q < 8; ++q )
22903 //Z_scripterrlog("FFscript blit() ri->d[%d] is: %d\n", q, ri->d[q]);
22904 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+13);
22905 break;
22906 }
22907
22908 case BMPWRITETILE:
22909 {
22910 19821648 set_user_bitmap_command_args(j, 6);
22911 19821648 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
22912 19821648 break;
22913 }
22914 case BMPDITHER:
22915 {
22916 set_user_bitmap_command_args(j, 5);
22917 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22918 break;
22919 }
22920 case BMPMASKDRAW:
22921 {
22922 906 set_user_bitmap_command_args(j, 3);
22923 906 script_drawing_commands[j][4] = 0x01 * 10000L;
22924 906 script_drawing_commands[j][5] = 0xFF * 10000L;
22925 906 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22926 906 break;
22927 }
22928 case BMPMASKDRAW2:
22929 {
22930 set_user_bitmap_command_args(j, 4);
22931 script_drawing_commands[j][5] = script_drawing_commands[j][4];
22932 script_drawing_commands[j][0] = BMPMASKDRAW;
22933 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22934 break;
22935 }
22936 case BMPMASKDRAW3:
22937 {
22938 set_user_bitmap_command_args(j, 5);
22939 script_drawing_commands[j][0] = BMPMASKDRAW;
22940 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22941 break;
22942 }
22943 case BMPMASKBLIT:
22944 {
22945 set_user_bitmap_command_args(j, 4);
22946 script_drawing_commands[j][5] = 0x01 * 10000L;
22947 script_drawing_commands[j][6] = 0xFF * 10000L;
22948 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22949 break;
22950 }
22951 case BMPMASKBLIT2:
22952 {
22953 set_user_bitmap_command_args(j, 5);
22954 script_drawing_commands[j][6] = script_drawing_commands[j][5];
22955 script_drawing_commands[j][0] = BMPMASKBLIT;
22956 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22957 break;
22958 }
22959 case BMPMASKBLIT3:
22960 {
22961 set_user_bitmap_command_args(j, 6);
22962 script_drawing_commands[j][0] = BMPMASKBLIT;
22963 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
22964 break;
22965 }
22966 case BMPREPLCOLOR:
22967 case BMPSHIFTCOLOR:
22968 {
22969 7323 set_user_bitmap_command_args(j, 4);
22970 7323 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22971 7323 break;
22972 }
22973
22974 case DRAWLIGHT_CONE:
22975 case DRAWLIGHT_CIRCLE:
22976 case DRAWLIGHT_SQUARE:
22977 {
22978 // These draw commands implicitly draw at the SPLAYER_DARKROOM_UNDER timing.
22979 // Shift the given args up by one.
22980 int num_args = script_command == DRAWLIGHT_CONE ? 8 : 7;
22981 set_drawing_command_args(j, num_args);
22982 for (int i = num_args; i >= 1; i--)
22983 script_drawing_commands[j][i + 1] = script_drawing_commands[j][i];
22984 script_drawing_commands[j][1] = SPLAYER_DARKROOM_UNDER * 10000;
22985 break;
22986 }
22987 }
22988
22989 int bmp_target;
22990
2/2
✓ Branch 0 taken 45321201 times.
✓ Branch 1 taken 53665602 times.
98986803 if (is_screen_draw)
22991 45321201 bmp_target = zscriptDrawingRenderTarget->GetCurrentRenderTarget() + 10;
22992 else
22993 53665602 bmp_target = script_drawing_commands[j][DRAWCMD_BMP_TARGET];
22994
22995 197973606 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_target);
22996 98986803 script_drawing_commands[j].draw_origin = draw_origin;
22997 98986803 script_drawing_commands[j].draw_origin_target = draw_origin_target;
22998
22999 98986803 script_drawing_commands.mark_dirty(script_drawing_commands[j][1]/10000);
23000 98986803 }
23001
23002 7069332 void do_set_rendertarget(bool)
23003 {
23004 7069332 int32_t target = int32_t(SH::read_stack(ri->sp) / 10000);
23005 7069332 zscriptDrawingRenderTarget->SetCurrentRenderTarget(target);
23006 7069332 }
23007
23008 339164 void do_sfx(const bool v)
23009 {
23010 339164 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23011
23012
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 339160 times.
339164 if(BC::checkSFXID(ID) != SH::_NoError)
23013 4 return;
23014
23015 339160 sfx(ID);
23016 339164 }
23017
23018 14 void do_sfx_ex(const bool restart)
23019 {
23020 14 int32_t ID = SH::read_stack(ri->sp + 4) / 10000;
23021 14 int32_t vol = vbound(SH::read_stack(ri->sp + 3), 0, 10000 * 100);
23022 14 int32_t pan = vbound(SH::read_stack(ri->sp + 2)/10000 + 128, 0, 255);
23023 14 int32_t freq = SH::read_stack(ri->sp + 1);
23024 14 bool loop = SH::read_stack(ri->sp) / 10000;
23025
23026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (BC::checkSFXID(ID) != SH::_NoError)
23027 return;
23028
23029
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if (!restart && !sfx_allocated(ID))
23030 return;
23031
23032 14 sfx(ID, pan, loop, restart, vol, freq);
23033 14 }
23034
23035 static int get_sfx_completion()
23036 {
23037 int32_t ID = get_register(sarg1) / 10000;
23038
23039 if (!sfx_allocated(ID))
23040 {
23041 return -10000;
23042 }
23043
23044 int sample_pos = voice_get_position(sfx_voice[ID]);
23045 if (sample_pos < 0)
23046 {
23047 return -10000;
23048 }
23049
23050 uint32_t sample_length = sfx_get_length(ID);
23051 uint64_t res = ((uint64_t)sample_pos * 10000 * 100) / sample_length;
23052 return int32_t(res);
23053 }
23054
23055 void do_get_sfx_completion()
23056 {
23057 int32_t ID = get_register(sarg1) / 10000;
23058 if (replay_is_active())
23059 replay_step_comment(fmt::format("ID {}", ID));
23060 int32_t value = replay_get_state(ReplayStateType::SfxPosition, get_sfx_completion);
23061 set_register(sarg1, value);
23062 }
23063
23064 void FFScript::AlloffLimited(int32_t flagset)
23065 {
23066 clear_bitmap(msg_txt_display_buf);
23067 clear_bitmap(msg_bg_display_buf);
23068 clear_bitmap(msg_portrait_display_buf);
23069 set_clip_state(msg_txt_display_buf, 1);
23070 set_clip_state(msg_bg_display_buf, 1);
23071 set_clip_state(msg_portrait_display_buf, 1);
23072
23073
23074 clear_bitmap(pricesdisplaybuf);
23075 set_clip_state(pricesdisplaybuf, 1);
23076
23077 if(items.idCount(iPile))
23078 {
23079 loadlvlpal(DMaps[cur_dmap].color);
23080 }
23081
23082 /*
23083
23084 #define warpFlagCLEARITEMS 0x200
23085 #define warpFlagCLEARGUYS 0x400
23086 #define warpFlagCLEARLWEAPONS 0x800
23087 #define warpFlagCLEAREWEAPONS 0x1000
23088 #define warpFlagCLEARHOOKSHOT 0x2000
23089 #define warpFlagCLEARDECORATIONS 0x4000
23090 #define warpFlagCLEARPARTICLES 0x8000
23091 */
23092
23093 if ( (flagset&warpFlagCLEARITEMS) ) items.clear();
23094 if ( (flagset&warpFlagCLEARGUYS) ) guys.clear();
23095 if ( (flagset&warpFlagCLEARLWEAPONS) ) Lwpns.clear();
23096 if ( (flagset&warpFlagCLEAREWEAPONS) ) Ewpns.clear();
23097 if ( (flagset&warpFlagCLEARHOOKSHOT) )
23098 {
23099 chainlinks.clear();
23100 Hero.reset_hookshot();
23101 }
23102 if ( (flagset&warpFlagCLEARDECORATIONS) ) decorations.clear();
23103 if ( (flagset&warpFlagCLEARPARTICLES) ) particles.clear();
23104 clearScriptHelperData();
23105
23106
23107
23108 clearScriptHelperData();
23109
23110 lensclk = 0;
23111 lensid=-1;
23112 drawguys=true;
23113 down_control_states[btnUp] =
23114 down_control_states[btnDown] =
23115 down_control_states[btnLeft] =
23116 down_control_states[btnRight] =
23117 down_control_states[btnA] =
23118 down_control_states[btnB] =
23119 down_control_states[btnS] = true;
23120
23121 if(watch && !cheat_superman)
23122 {
23123 Hero.setClock(false);
23124 }
23125
23126 watch=freeze_guys=loaded_guys=blockpath=false;
23127
23128 activation_counters.clear();
23129 activation_counters_ffc.clear();
23130 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
23131 get_screen_state(scr->screen).loaded_enemies = false;
23132 });
23133
23134 sle_clk=0;
23135
23136 if(usebombpal)
23137 {
23138 memcpy(RAMpal, tempbombpal, PAL_SIZE*sizeof(RGB));
23139 refreshpal=true;
23140 usebombpal=false;
23141 }
23142
23143
23144 }
23145
23146 192 void doWarpEffect(int32_t warpEffect, bool out)
23147 {
23148
4/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 8 times.
192 switch(warpEffect)
23149 {
23150 case warpEffectZap:
23151 if(out) zapout();
23152 else zapin();
23153 break;
23154 case warpEffectWave:
23155
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(out) wavyout(false);
23156 12 else wavyin();
23157 24 break;
23158 case warpEffectInstant:
23159
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(out) blackscr(30,true);
23160 4 break;
23161 case warpEffectMozaic:
23162 //!TODO Unimplemented
23163 break;
23164 case warpEffectOpen:
23165
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if(out) closescreen();
23166 4 else openscreen();
23167 8 break;
23168 }
23169 192 }
23170
23171 14 void FFScript::queueWarp(int32_t wtype, int32_t tdm, int32_t tscr, int32_t wx, int32_t wy,
23172 int32_t weff, int32_t wsfx, int32_t wflag, int32_t wdir)
23173 {
23174 14 warpex[wexActive] = 1;
23175 14 warpex[wexType] = wtype;
23176 14 warpex[wexDMap] = tdm;
23177 14 warpex[wexScreen] = tscr;
23178 14 warpex[wexX] = wx;
23179 14 warpex[wexY] = wy;
23180 14 warpex[wexEffect] = weff;
23181 14 warpex[wexSound] = wsfx;
23182 14 warpex[wexFlags] = wflag;
23183 14 warpex[wexDir] = wdir;
23184 14 }
23185
23186 106 bool FFScript::warp_player(int32_t warpType, int32_t dmap, int32_t screen, int32_t warpDestX, int32_t warpDestY, int32_t warpEffect, int32_t warpSound, int32_t warpFlags, int32_t heroFacesDir)
23187 {
23188 if(DEVLOGGING)
23189 {
23190 zprint("FFScript::warp_player() arg %s is: %d \n", "warpType", warpType);
23191 zprint("FFScript::warp_player() arg %s is: %d \n", "dmap", dmap);
23192 zprint("FFScript::warp_player() arg %s is: %d \n", "screen", screen);
23193 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestX", warpDestX);
23194 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestY", warpDestY);
23195 zprint("FFScript::warp_player() arg %s is: %d \n", "warpEffect", warpEffect);
23196 zprint("FFScript::warp_player() arg %s is: %d \n", "warpSound", warpSound);
23197 zprint("FFScript::warp_player() arg %s is: %d \n", "warpFlags", warpFlags);
23198 zprint("FFScript::warp_player() arg %s is: %d \n", "heroFacesDir", heroFacesDir);
23199 }
23200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if ( ((unsigned)dmap) >= MAXDMAPS )
23201 {
23202 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", dmap);
23203 return false;
23204 }
23205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if ( ((unsigned)screen) >= MAPSCRS )
23206 {
23207 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", screen);
23208 return false;
23209 }
23210 //Extra sanity guard.
23211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if ( map_screen_index(DMaps[dmap].map, screen + DMaps[dmap].xoff) >= (int32_t)TheMaps.size() )
23212 {
23213 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
23214 return false;
23215 }
23216 106 byte t = 0;
23217 106 t=(cur_screen<128)?0:1;
23218 106 bool overlay=false;
23219 106 bool intradmap = (dmap == cur_dmap);
23220 106 int32_t olddmap = cur_dmap;
23221 //if ( intradmap )
23222 //{
23223 // initZScriptDMapScripts(); //Not needed.
23224 //}
23225
23226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if ( warpType == wtNOWARP ) { Z_eventlog("Used a Cancel Warped to DMap %d: %s, screen %d", cur_dmap, DMaps[cur_dmap].name,cur_screen); return false; }
23227 106 int32_t dest_map = DMaps[dmap].map;
23228 106 int32_t mapID = dest_map + 1;
23229 106 int32_t dest_dmap_xoff = DMaps[dmap].xoff;
23230 106 int32_t dest_screen = dest_dmap_xoff + screen;
23231 //mapscr *m = &TheMaps[mapID * MAPSCRS + scrID];
23232
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 mapscr *m = &TheMaps[(zc_max((mapID)-1,0) * MAPSCRS + dest_screen)];
23233
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 if ( warpFlags&warpFlagNOSTEPFORWARD ) FFCore.temp_no_stepforward = 1;
23234 106 int32_t wx = 0, wy = 0;
23235
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 85 times.
106 if ( warpDestX < 0 )
23236 {
23237 if(DEVLOGGING) zprint("WarpEx() was set to warp return point:%d\n", warpDestY);
23238
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 10 times.
85 if ( (unsigned)warpDestY < 4 )
23239 {
23240 75 wx = m->warpreturnx[warpDestY];
23241 75 wy = m->warpreturny[warpDestY];
23242 if(DEVLOGGING)
23243 {
23244 zprint("WarpEx Return Point X is: %d\n",wx);
23245 zprint("WarpEx Return Point Y is: %d\n",wy);
23246 }
23247 75 }
23248 else
23249 {
23250
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if ( warpDestY == 5 || warpDestY < 0)
23251 {
23252 //Pit warp
23253 10 wx = Hero.getX();
23254 10 wy = Hero.getY();
23255 10 }
23256 else
23257 {
23258 Z_scripterrlog("Invalid Warp Return Square Type (%d) provided as an arg to Hero->WarpEx().\n",warpDestY);
23259 return false;
23260 }
23261 }
23262 85 }
23263 else
23264 {
23265 region_t region;
23266 int rx, ry;
23267 21 calculate_region(dest_map, dest_screen, region, rx, ry);
23268
2/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
21 if ( (unsigned)warpDestX < region.width && (unsigned)warpDestY < region.height )
23269 {
23270 21 wx = warpDestX;
23271 21 wy = warpDestY;
23272 21 }
23273 else
23274 {
23275 Z_scripterrlog("Invalid pixel coordinates of x = %d, y = %d, supplied to Hero->WarpEx()\n",warpDestX,warpDestY);
23276 return false;
23277 }
23278 }
23279 //warp coordinates are wx, wy, not x, y! -Z
23280
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 52 times.
106 if ( !(warpFlags&warpFlagDONTKILLSCRIPTDRAWS) ) script_drawing_commands.Clear();
23281 //we also need to check if dmaps are sideview here! -Z
23282 //Likewise, we need to add that check to the normal Hero:;dowarp(0
23283 106 bool wasSideview = isSideViewGravity(t);
23284
23285 //int32_t last_entr_scr = -1;
23286 //int32_t last_entr_dmap = -1;
23287
23288
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 if ( warpType < wtEXIT ) warpType = wtIWARP; //Sanity check. We can't use wtCave, or wtPassage, with scritped warps at present.
23289 106 Hero.is_warping = true;
23290
2/5
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
106 switch(warpType)
23291 {
23292 case wtIWARP:
23293 case wtIWARPBLK:
23294 case wtIWARPOPEN:
23295 case wtIWARPZAP:
23296 case wtIWARPWAVE:
23297 {
23298 96 bool wasswimming = (Hero.getAction()==swimming);
23299 96 bool wassideswim = (Hero.getAction()==sideswimming);
23300 96 int32_t olddiveclk = Hero.diveclk;
23301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if ( !(warpFlags&warpFlagDONTCLEARSPRITES) )
23302 {
23303 96 ALLOFF();
23304 96 }
23305 else FFCore.AlloffLimited(warpFlags);
23306
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 78 times.
96 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
23307
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 42 times.
96 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
23308 96 sfx(warpSound);
23309
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(wasswimming)
23310 {
23311 Hero.setAction(swimming); FFCore.setHeroAction(swimming);
23312 Hero.diveclk = olddiveclk;
23313 }
23314
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(wassideswim)
23315 {
23316 Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);
23317 Hero.diveclk = 0;
23318 }
23319 96 doWarpEffect(warpEffect, true);
23320 96 int32_t c = DMaps[cur_dmap].color;
23321 96 bool changedlevel = false;
23322 96 bool changeddmap = false;
23323
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 70 times.
96 if(cur_dmap != dmap)
23324 {
23325 70 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23326 70 changeddmap = true;
23327 70 }
23328
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 52 times.
96 if(dlevel != DMaps[dmap].level)
23329 {
23330 52 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23331 52 changedlevel = true;
23332 52 }
23333 96 dlevel = DMaps[dmap].level;
23334 96 cur_dmap = dmap;
23335
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 70 times.
96 if(changeddmap)
23336 {
23337 70 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23338 70 }
23339
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 52 times.
96 if(changedlevel)
23340 {
23341 52 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23342 52 }
23343 96 cur_map = DMaps[cur_dmap].map;
23344 96 init_dmap();
23345 96 update_subscreens(dmap);
23346
23347 96 ringcolor(false);
23348
23349
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 70 times.
96 if(DMaps[cur_dmap].color != c)
23350 70 loadlvlpal(DMaps[cur_dmap].color);
23351
23352 96 lightingInstant(); // Also sets naturaldark
23353 96 int prev_screen = hero_screen;
23354 96 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
23355
23356 // In the case where we did not call ALLOFF, preserve the "enemies have spawned"
23357 // state for the new screen.
23358
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if (warpFlags&warpFlagDONTCLEARSPRITES)
23359 {
23360 if (get_screen_state(prev_screen).loaded_enemies)
23361 get_screen_state(hero_screen).loaded_enemies = true;
23362 }
23363
23364 96 Hero.x = (zfix)wx;
23365 96 Hero.y = (zfix)wy;
23366 96 update_viewport();
23367
23368
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 30 times.
96 switch(heroFacesDir)
23369 {
23370 case up:
23371 case down:
23372 case left:
23373 case right:
23374 66 Hero.dir = heroFacesDir;
23375 66 break;
23376 default:
23377
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if((int32_t)Hero.x==(zfix)0)
23378 {
23379 Hero.dir=right;
23380 }
23381
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if((int32_t)Hero.x==(zfix)240)
23382 {
23383 Hero.dir=left;
23384 }
23385
23386
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if((int32_t)Hero.y==(zfix)0)
23387 {
23388 Hero.dir=down;
23389 }
23390
23391
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if((int32_t)Hero.y==(zfix)160)
23392 {
23393 Hero.dir=up;
23394 }
23395 30 }
23396
23397 96 markBmap(Hero.dir^1, hero_screen);
23398
23399
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 96 times.
96 if(iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && _walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) && current_item(itype_flippers))
23400 {
23401 Hero.hopclk=0xFF;
23402 Hero.attackclk = Hero.charging = Hero.spins = 0;
23403 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
23404 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
23405 }
23406 else
23407 {
23408 96 Hero.setAction(none); FFCore.setHeroAction(none);
23409 }
23410
23411 //preloaded freeform combos
23412 96 ffscript_engine(true);
23413
23414 96 putscr(hero_scr, scrollbuf, 0, 0);
23415 96 putscrdoors(hero_scr, scrollbuf, 0, 0);
23416
23417 96 doWarpEffect(warpEffect, false);
23418 96 show_subscreen_life=true;
23419 96 show_subscreen_numbers=true;
23420
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 92 times.
96 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
23421 96 currcset=DMaps[cur_dmap].color;
23422 96 dointro();
23423 96 Hero.set_respawn_point();
23424 96 Hero.trySideviewLadder();
23425
23426 96 break;
23427 }
23428
23429
23430 case wtEXIT:
23431 {
23432 lighting(false,false,pal_litRESETONLY);//Reset permLit, and do nothing else; lighting was not otherwise called on a wtEXIT warp.
23433 ALLOFF();
23434 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
23435 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
23436 sfx(warpSound);
23437 blackscr(30,false);
23438 bool changedlevel = false;
23439 bool changeddmap = false;
23440 if(cur_dmap != dmap)
23441 {
23442 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23443 changeddmap = true;
23444 }
23445 if(dlevel != DMaps[dmap].level)
23446 {
23447 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23448 changedlevel = true;
23449 }
23450 dlevel = DMaps[dmap].level;
23451 cur_dmap = dmap;
23452 if(changeddmap)
23453 {
23454 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23455 }
23456 if(changedlevel)
23457 {
23458 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23459 }
23460 cur_map=DMaps[cur_dmap].map;
23461 init_dmap();
23462 update_subscreens(dmap);
23463 loadfullpal();
23464 ringcolor(false);
23465 loadlvlpal(DMaps[cur_dmap].color);
23466 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
23467
23468 if((hero_scr->flags&fDARK) && !get_qr(qr_NEW_DARKROOM))
23469 {
23470 if(get_qr(qr_FADE))
23471 {
23472 interpolatedfade();
23473 }
23474 else
23475 {
23476 loadfadepal((DMaps[cur_dmap].color)*pdLEVEL+poFADE3);
23477 }
23478
23479 darkroom=naturaldark=true;
23480 }
23481 else
23482 {
23483 darkroom=naturaldark=false;
23484 }
23485
23486
23487 //Move Hero's coordinates
23488 Hero.x = (zfix)wx;
23489 Hero.y = (zfix)wy;
23490 update_viewport();
23491
23492 //set his dir
23493 switch(heroFacesDir)
23494 {
23495 case up:
23496 case down:
23497 case left:
23498 case right:
23499 Hero.dir = heroFacesDir;
23500 break;
23501 default:
23502 Hero.dir=down;
23503 if((int32_t)Hero.x==(zfix)0)
23504 {
23505 Hero.dir=right;
23506 }
23507 if((int32_t)Hero.x==(zfix)240)
23508 {
23509 Hero.dir=left;
23510 }
23511
23512 if((int32_t)Hero.y==(zfix)0)
23513 {
23514 Hero.dir=down;
23515 }
23516
23517 if((int32_t)Hero.y==(zfix)160)
23518 {
23519 Hero.dir=up;
23520 }
23521 }
23522
23523 if(dlevel)
23524 {
23525 // reset enemy kill counts
23526 for(int32_t i=0; i<128; i++)
23527 {
23528 int mi = mapind(cur_map, i);
23529 game->guys[mi] = 0;
23530 game->maps[mi] &= ~mTMPNORET;
23531 }
23532 }
23533
23534 markBmap(Hero.dir^1, hero_screen);
23535 //preloaded freeform combos
23536 ffscript_engine(true);
23537 Hero.reset_hookshot();
23538
23539 if(isdungeon())
23540 {
23541 openscreen();
23542 if(get_er(er_SHORTDGNWALK)==0 && get_qr(qr_SHORTDGNWALK)==0)
23543 Hero.stepforward(Hero.diagonalMovement?11:12, false);
23544 else
23545 // Didn't walk as far pre-1.93, and some quests depend on that
23546 Hero.stepforward(8, false);
23547 }
23548 else
23549 {
23550 openscreen();
23551 }
23552
23553 show_subscreen_life=true;
23554 show_subscreen_numbers=true;
23555 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC))Play_Level_Music();
23556 currcset=DMaps[cur_dmap].color;
23557 dointro();
23558 Hero.set_respawn_point();
23559 Hero.trySideviewLadder();
23560
23561 for(int32_t i=0; i<6; i++)
23562 visited[i]=-1;
23563
23564 //last_entr_scr = scrID;
23565 //last_entr_dmap = dmapID;
23566
23567 break;
23568
23569 }
23570 case wtSCROLL: // scrolling warp
23571 {
23572 10 int32_t c = DMaps[cur_dmap].color;
23573 10 scrolling_dmap = cur_dmap;
23574 10 scrolling_map = cur_map;
23575 10 cur_map = DMaps[dmap].map;
23576 10 update_subscreens(dmap);
23577
23578 10 dlevel = DMaps[dmap].level;
23579 //check if Hero has the map for the new location before updating the subscreen. ? -Z
23580 //This works only in one direction, if Hero had a map, to not having one.
23581 //If Hero does not have a map, and warps somewhere where he does, then the map still briefly shows.
23582 10 update_subscreens(dmap);
23583
23584 // if ( has_item(itype_map, dlevel) )
23585 // {
23586 // //Blank the map during an intra-dmap scrolling warp.
23587 // dlevel = -1; //a hack for the minimap. This works!! -Z
23588 // }
23589
23590 // fix the scrolling direction, if it was a tile or instant warp
23591 10 Hero.sdir = vbound(Hero.dir,0,3);
23592
23593
23594 10 Hero.scrollscr(Hero.sdir, screen+DMaps[dmap].xoff, dmap);
23595 10 bool changedlevel = false;
23596 10 bool changeddmap = false;
23597
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(cur_dmap != dmap)
23598 {
23599 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23600 changeddmap = true;
23601 }
23602
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(dlevel != DMaps[dmap].level)
23603 {
23604 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23605 changedlevel = true;
23606 }
23607 10 dlevel = DMaps[dmap].level;
23608 10 cur_dmap = dmap;
23609
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changeddmap)
23610 {
23611 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23612 }
23613
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changedlevel)
23614 {
23615 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23616 }
23617
23618 10 Hero.reset_hookshot();
23619
23620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(!intradmap)
23621 {
23622
5/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
10 if(((wx>0||wy>0)||(get_qr(qr_WARPSIGNOREARRIVALPOINT)))&&(!get_qr(qr_NOSCROLLCONTINUE))&&(!(hero_scr->flags6&fNOCONTINUEHERE)))
23623 {
23624
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
10 if(dlevel)
23625 {
23626 6 lastentrance = cur_screen;
23627 6 }
23628 else
23629 {
23630 4 lastentrance = DMaps[cur_dmap].cont + DMaps[cur_dmap].xoff;
23631 }
23632
23633 10 lastentrance_dmap = dmap;
23634 10 }
23635 10 }
23636
23637
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(DMaps[cur_dmap].color != c)
23638 {
23639 lighting(false, true);
23640 }
23641
23642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
23643 10 currcset=DMaps[cur_dmap].color;
23644 10 dointro();
23645 10 break;
23646 }
23647 //Cannot use these types with scripts, or with strings.
23648 case wtCAVE:
23649 case wtPASS:
23650 case wtWHISTLE:
23651 default:
23652 {
23653 Z_scripterrlog("Invalid warp type (%d) supplied to Hero->WarpEx()!. Cannot warp!!\n", warpType);
23654 Hero.is_warping = false;
23655 return false;
23656 }
23657 }
23658 // Stop Hero from drowning!
23659
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 if(Hero.getAction()==drowning)
23660 {
23661 Hero.drownclk=0;
23662 Hero.setAction(none); FFCore.setHeroAction(none);
23663 }
23664
23665 // But keep him swimming if he ought to be!
23666
3/8
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 106 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 106 times.
✗ Branch 7 not taken.
106 if(Hero.getAction()!=rafting && iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && (_walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) || get_qr(qr_DROWN))
23667 && (current_item(itype_flippers)) && (Hero.getAction()!=inwind))
23668 {
23669 Hero.hopclk=0xFF;
23670 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
23671 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
23672 }
23673
23674 106 newscr_clk=frame;
23675 106 activated_timed_warp=false;
23676 106 eat_buttons();
23677
23678
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 26 times.
106 if(warpType!=wtIWARP) { Hero.attackclk=0; }
23679
23680 106 Hero.didstuff=0;
23681 106 Hero.usecounts.clear();
23682 106 map_bkgsfx(true);
23683 106 loadside=Hero.dir^1;
23684 106 whistleclk=-1;
23685
23686
2/4
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
106 if(((int32_t)Hero.z>0 || (int32_t)Hero.fakez>0) && isSideViewHero())
23687 {
23688 Hero.y-=Hero.z;
23689 Hero.y-=Hero.fakez;
23690 Hero.z=0;
23691 Hero.fakez=0;
23692 }
23693
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 105 times.
106 else if(!isSideViewHero())
23694 {
23695 105 Hero.fall=0;
23696 105 Hero.fakefall=0;
23697 105 }
23698
23699 // If warping between top-down and sideview screens,
23700 // fix enemies that are carried over by Full Screen Warp
23701 106 const bool tmpscr_is_sideview = isSideViewGravity();
23702
23703
3/4
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 105 times.
✓ Branch 3 taken 1 times.
106 if(!wasSideview && tmpscr_is_sideview)
23704 {
23705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 for(int32_t i=0; i<guys.Count(); i++)
23706 {
23707 if(guys.spr(i)->z > 0)
23708 {
23709 guys.spr(i)->y -= guys.spr(i)->z;
23710 guys.spr(i)->z = 0;
23711 }
23712
23713 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
23714 guys.spr(i)->yofs += 2;
23715 }
23716 1 }
23717
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
105 else if(wasSideview && !tmpscr_is_sideview)
23718 {
23719 for(int32_t i=0; i<guys.Count(); i++)
23720 {
23721 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
23722 guys.spr(i)->yofs -= 2;
23723 }
23724 }
23725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if ( warpType == wtEXIT )
23726 {
23727 game->set_continue_scrn(cur_screen);
23728 game->set_continue_dmap(dmap);
23729 lastentrance = cur_screen;
23730 lastentrance_dmap = dmap;
23731 }
23732 else
23733 {
23734
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 4 times.
106 if ( (warpFlags&warpFlagSETENTRANCESCREEN) ) lastentrance = cur_screen;
23735
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 4 times.
106 if ( (warpFlags&warpFlagSETENTRANCEDMAP) ) lastentrance_dmap = dmap;
23736
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 4 times.
106 if ( (warpFlags&warpFlagSETCONTINUESCREEN) ) game->set_continue_scrn(cur_screen);
23737
2/2
✓ Branch 0 taken 102 times.
✓ Branch 1 taken 4 times.
106 if ( (warpFlags&warpFlagSETCONTINUEDMAP) ) game->set_continue_dmap(dmap);
23738 }
23739
1/2
✓ Branch 0 taken 106 times.
✗ Branch 1 not taken.
106 if(hero_scr->flags4&fAUTOSAVE)
23740 {
23741 save_game(true,0);
23742 }
23743
23744
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 1 times.
106 if(hero_scr->flags6&fCONTINUEHERE)
23745 {
23746 1 lastentrance_dmap = cur_dmap;
23747 1 lastentrance = home_screen;
23748 1 }
23749
23750 106 update_subscreens();
23751 106 verifyBothWeapons();
23752 212 Z_eventlog("Warped to DMap %d: %s, screen %d, via %s.\n", cur_dmap, DMaps[cur_dmap].name,cur_screen,
23753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
212 warpType==wtEXIT ? "Entrance/Exit" :
23754
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 96 times.
106 warpType==wtSCROLL ? "Scrolling Warp" :
23755 96 warpType==wtNOWARP ? "Cancel Warp" :
23756 "Insta-Warp");
23757
23758 106 eventlog_mapflags();
23759
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
106 if (((warpFlags&warpFlagDONTRESTARTDMAPSCRIPT) != 0) == (get_qr(qr_SCRIPT_WARPS_DMAP_SCRIPT_TOGGLE) != 0)|| olddmap != cur_dmap) //Changed DMaps, or needs to reset the script
23760 {
23761 106 FFScript::deallocateAllScriptOwned(ScriptType::DMap, olddmap);
23762 106 initZScriptDMapScripts();
23763 106 }
23764 106 Hero.is_warping = false;
23765
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 90 times.
106 if(!get_qr(qr_SCROLLWARP_NO_RESET_FRAME))
23766 90 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
23767 106 return true;
23768 106 }
23769
23770 2004 void FFScript::do_adjustvolume(const bool v)
23771 {
23772
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (get_qr(qr_OLD_SCRIPT_VOLUME))
23773 {
23774 2004 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
23775 2004 float pct = perc / 100.0;
23776 2004 float temp_midi = 0;
23777 2004 float temp_digi = 0;
23778 2004 float temp_mus = 0;
23779
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MIDI_VOLUME))
23780 {
23781 4 temp_midi = do_getMIDI_volume();
23782 4 usr_midi_volume = do_getMIDI_volume();
23783 4 SetFFEngineFlag(FFCORE_SCRIPTED_MIDI_VOLUME, true);
23784 4 }
23785 else
23786 {
23787 2000 temp_midi = (float)usr_midi_volume;
23788 }
23789
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_DIGI_VOLUME))
23790 {
23791 4 temp_digi = do_getDIGI_volume();
23792 4 usr_digi_volume = do_getDIGI_volume();
23793 4 SetFFEngineFlag(FFCORE_SCRIPTED_DIGI_VOLUME, true);
23794 4 }
23795 else
23796 {
23797 2000 temp_digi = (float)usr_digi_volume;
23798 }
23799
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME))
23800 {
23801 4 temp_mus = do_getMusic_volume();
23802 4 usr_music_volume = do_getMusic_volume();
23803 4 SetFFEngineFlag(FFCORE_SCRIPTED_MUSIC_VOLUME, true);
23804 4 }
23805 else
23806 {
23807 2000 temp_mus = (float)usr_music_volume;
23808 }
23809
23810 2004 temp_midi *= pct;
23811 2004 temp_digi *= pct;
23812 2004 temp_mus *= pct;
23813 2004 do_setMIDI_volume((int32_t)temp_midi);
23814 2004 do_setDIGI_volume((int32_t)temp_digi);
23815 2004 do_setMusic_volume((int32_t)temp_mus);
23816 2004 }
23817 else
23818 {
23819 int32_t perc = SH::get_arg(sarg1, v);
23820 FFCore.usr_music_volume = vbound(perc, 0, 10000 * 100);
23821
23822 if (zcmusic != NULL)
23823 {
23824 if (zcmusic->playing != ZCM_STOPPED)
23825 {
23826 int32_t temp_volume = emusic_volume;
23827 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
23828 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
23829 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
23830 zcmusic_play(zcmusic, temp_volume);
23831 return;
23832 }
23833 }
23834 else if (currmidi > -1)
23835 {
23836 jukebox(currmidi);
23837 master_volume(digi_volume, midi_volume);
23838 }
23839 }
23840 2004 }
23841
23842 void FFScript::do_adjustsfxvolume(const bool v)
23843 {
23844 if (get_qr(qr_OLD_SCRIPT_VOLUME))
23845 {
23846 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
23847 float pct = perc / 100.0;
23848 float temp_sfx = 0;
23849 if (!(coreflags & FFCORE_SCRIPTED_SFX_VOLUME))
23850 {
23851 temp_sfx = do_getSFX_volume();
23852 usr_sfx_volume = (int32_t)temp_sfx;
23853 SetFFEngineFlag(FFCORE_SCRIPTED_SFX_VOLUME, true);
23854 }
23855 else
23856 {
23857 temp_sfx = (float)usr_sfx_volume;
23858 }
23859 temp_sfx *= pct;
23860 do_setSFX_volume((int32_t)temp_sfx);
23861 }
23862 else
23863 {
23864 int32_t perc = SH::get_arg(sarg1, v);
23865 FFCore.usr_sfx_volume = vbound(perc, 0, 10000 * 100);
23866 }
23867 }
23868
23869
23870 63829 void do_midi(bool v)
23871 {
23872 63829 int32_t MIDI = SH::get_arg(sarg1, v) / 10000;
23873
23874
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 63786 times.
63829 if(MIDI == 0)
23875 43 music_stop();
23876 else
23877 63786 jukebox(MIDI + (ZC_MIDI_COUNT - 1));
23878 63829 }
23879
23880
23881 1 void stop_sfx(const bool v)
23882 {
23883 1 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23884 1 int32_t sfx = (int32_t)ID;
23885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(BC::checkSFXID(ID) != SH::_NoError)
23886 return;
23887 1 stop_sfx(sfx);
23888 1 }
23889
23890 void pause_sfx(const bool v)
23891 {
23892 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23893 int32_t sfx = (int32_t)ID;
23894 if(BC::checkSFXID(ID) != SH::_NoError)
23895 return;
23896 pause_sfx(sfx);
23897 }
23898
23899 void resume_sfx(const bool v)
23900 {
23901 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23902 int32_t sfx = (int32_t)ID;
23903 if(BC::checkSFXID(ID) != SH::_NoError)
23904 return;
23905 resume_sfx(sfx);
23906 }
23907
23908
23909
23910 178 void do_enh_music(bool v)
23911 {
23912 178 int32_t arrayptr = SH::get_arg(sarg1, v);
23913 178 int32_t track = (SH::get_arg(sarg2, v) / 10000)-1;
23914
23915
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 if(arrayptr == 0)
23916 music_stop();
23917 else // Pointer to a string..
23918 {
23919 178 string filename_str;
23920 char filename_char[256];
23921 bool ret;
23922
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 ArrayH::getString(arrayptr, filename_str, 256);
23923 178 strncpy(filename_char, filename_str.c_str(), 255);
23924 178 filename_char[255]='\0';
23925
2/4
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
✗ Branch 3 not taken.
178 ret=try_zcmusic(filename_char, qstpath, track, -1000, get_emusic_volume());
23926
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 set_register(sarg2, ret ? 10000 : 0);
23927 178 }
23928 178 }
23929
23930 5 void do_enh_music_crossfade()
23931 {
23932 5 int32_t arrayptr = SH::read_stack(ri->sp + 5);
23933 5 int32_t track = SH::read_stack(ri->sp + 4) / 10000;
23934
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeoutframes = zc_max(SH::read_stack(ri->sp + 3) / 10000, 0);
23935
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeinframes = zc_max(SH::read_stack(ri->sp + 2) / 10000, 0);
23936 5 int32_t fademiddleframes = SH::read_stack(ri->sp + 1) / 10000;
23937 5 int32_t startpos = SH::read_stack(ri->sp);
23938
23939
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (arrayptr == 0)
23940 {
23941 bool ret = play_enh_music_crossfade(NULL, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos);
23942 ri->d[rEXP1] = ret ? 10000 : 0;
23943 }
23944 else
23945 {
23946 5 string filename_str;
23947 char filename_char[256];
23948
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 ArrayH::getString(arrayptr, filename_str, 256);
23949 5 strncpy(filename_char, filename_str.c_str(), 255);
23950 5 filename_char[255] = '\0';
23951
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 bool ret = play_enh_music_crossfade(filename_char, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos, true);
23952 5 ri->d[rEXP1] = ret ? 10000 : 0;
23953 5 }
23954 5 }
23955
23956 bool FFScript::doing_dmap_enh_music(int32_t dm)
23957 {
23958 if (DMaps[dm].tmusic[0] != 0)
23959 {
23960 if (zcmusic != NULL)
23961 {
23962 if (strcmp(zcmusic->filename, DMaps[dm].tmusic) == 0)
23963 {
23964 switch (zcmusic_get_type(zcmusic))
23965 {
23966 case ZCMF_OGG:
23967 case ZCMF_MP3:
23968 return true;
23969 case ZCMF_DUH:
23970 case ZCMF_GME:
23971 if (zcmusic->track == DMaps[dm].tmusictrack)
23972 {
23973 return true;
23974 }
23975 }
23976 }
23977 }
23978 }
23979 return false;
23980 }
23981
23982 38635 bool FFScript::can_dmap_change_music(int32_t dm)
23983 {
23984
1/4
✓ Branch 0 taken 38635 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38635 switch (music_update_cond)
23985 {
23986 case MUSIC_UPDATE_SCREEN:
23987 38635 return true;
23988 case MUSIC_UPDATE_DMAP:
23989 return dm != -1 && dm != cur_dmap;
23990 case MUSIC_UPDATE_LEVEL:
23991 return dm != -1 && DMaps[dm].level != DMaps[cur_dmap].level;
23992 }
23993 return false;
23994 38635 }
23995
23996 void FFScript::do_set_music_position(const bool v)
23997 {
23998 int32_t newposition = SH::get_arg(sarg1, v);
23999
24000 set_zcmusicpos(newposition);
24001 }
24002
24003 void FFScript::do_get_music_position()
24004 {
24005 int32_t pos = replay_get_state(ReplayStateType::MusicPosition, [](){
24006 return zcmusic_get_curpos(zcmusic);
24007 });
24008 set_register(sarg1, pos);
24009 }
24010
24011 void FFScript::do_set_music_speed(const bool v)
24012 {
24013 int32_t newspeed = SH::get_arg(sarg1, v);
24014 set_zcmusicspeed(newspeed);
24015 }
24016
24017 void FFScript::do_get_music_length()
24018 {
24019 int32_t len = get_zcmusiclen();
24020 set_register(sarg1, len);
24021 }
24022
24023 3 void FFScript::do_set_music_loop()
24024 {
24025 3 double start = (get_register(sarg1) / 10000.0);
24026 3 double end = (get_register(sarg2) / 10000.0);
24027
24028 3 set_zcmusicloop(start, end);
24029 3 }
24030
24031 236 void do_get_enh_music_filename(const bool v)
24032 {
24033 236 int32_t ID = SH::get_arg(sarg1, v) / 10000;
24034 236 int32_t arrayptr = get_register(sarg2);
24035
24036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236 times.
236 if(BC::checkDMapID(ID) != SH::_NoError)
24037 return;
24038
24039
3/6
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 236 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 236 times.
✗ Branch 5 not taken.
236 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
24040 Z_scripterrlog("Array supplied to 'Game->GetDMapMusicFilename' not large enough\n");
24041 236 }
24042
24043 140 void do_get_enh_music_track(const bool v)
24044 {
24045 140 int32_t ID = SH::get_arg(sarg1, v) / 10000;
24046
24047
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 132 times.
140 if(BC::checkDMapID(ID) != SH::_NoError)
24048 8 return;
24049
24050 132 set_register(sarg1, (DMaps[ID].tmusictrack+1)*10000);
24051 140 }
24052
24053 3783 void do_set_dmap_enh_music(const bool v)
24054 {
24055 3783 int32_t ID = SH::read_stack(ri->sp + 2) / 10000;
24056 3783 int32_t arrayptr = SH::read_stack(ri->sp + 1);
24057 3783 int32_t track = (SH::read_stack(ri->sp + 0) / 10000)-1;
24058 3783 string filename_str;
24059
24060
2/4
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3783 times.
✗ Branch 3 not taken.
3783 if(BC::checkDMapID(ID) != SH::_NoError)
24061 return;
24062
24063
1/2
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
3783 ArrayH::getString(arrayptr, filename_str, 56);
24064 3783 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
24065 3783 DMaps[ID].tmusic[55]='\0';
24066 3783 DMaps[ID].tmusictrack=track;
24067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3783 times.
3783 }
24068
24069
24070
24071
24072
24073
24074 ///----------------------------------------------------------------------------------------------------//
24075 //Array & string related
24076
24077 303069082 void do_arraysize()
24078 {
24079 303069082 int32_t arrayptr = get_register(sarg1);
24080 303069082 ri->d[rEXP1] = ArrayH::getSize(arrayptr) * 10000;
24081 303069082 }
24082
24083 void do_tobyte()
24084 {
24085 int32_t b1 = get_register(sarg1) / 10000;
24086 byte b2 = b1;
24087 set_register(sarg1, b2 * 10000);
24088 }
24089
24090 void do_tosignedbyte()
24091 {
24092 int32_t b1 = get_register(sarg1) / 10000;
24093 signed char b2 = b1;
24094 set_register(sarg1, b2 * 10000);
24095 }
24096
24097 void do_tointeger()
24098 {
24099 int32_t b1 = get_register(sarg1) / 10000;
24100 set_register(sarg1, b1 * 10000);
24101 }
24102
24103 291091 void do_floor()
24104 {
24105 291091 set_register(sarg1, zslongToFix(get_register(sarg1)).doFloor().getZLong());
24106 291091 }
24107
24108 void do_trunc()
24109 {
24110 set_register(sarg1, zslongToFix(get_register(sarg1)).doTrunc().getZLong());
24111 }
24112
24113 6877 void do_ceiling()
24114 {
24115 6877 set_register(sarg1, zslongToFix(get_register(sarg1)).doCeil().getZLong());
24116 6877 }
24117
24118 void do_round()
24119 {
24120 set_register(sarg1, zslongToFix(get_register(sarg1)).doRound().getZLong());
24121 }
24122
24123 void do_roundaway()
24124 {
24125 set_register(sarg1, zslongToFix(get_register(sarg1)).doRoundAway().getZLong());
24126 }
24127
24128 void do_toword()
24129 {
24130 int32_t b1 = get_register(sarg1) / 10000;
24131 word b2 = b1;
24132 set_register(sarg1, b2 * 10000);
24133 }
24134
24135 void do_toshort()
24136 {
24137 int32_t b1 = get_register(sarg1) / 10000;
24138 int16_t b2 = b1;
24139 set_register(sarg1, b2 * 10000);
24140 }
24141
24142 //Set npc and item names t.b.a. -Z
24143
24144 2768 void do_getitemname()
24145 {
24146 2768 int32_t arrayptr = get_register(sarg1);
24147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2768 times.
2768 if(unsigned(ri->idata) >= MAXITEMS)
24148 {
24149 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
24150 return;
24151 }
24152
24153
3/6
✓ Branch 0 taken 2768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2768 times.
✗ Branch 5 not taken.
2768 if(ArrayH::setArray(arrayptr, item_string[ri->idata]) == SH::_Overflow)
24154 Z_scripterrlog("Array supplied to 'itemdata->GetName' not large enough\n");
24155 2768 }
24156
24157 10105627 void do_getffcscript()
24158 {
24159 10105627 do_get_script_index_by_name(name_to_slot_index_ffcmap);
24160 10105627 }
24161
24162 80 void do_getitemscript()
24163 {
24164 80 do_get_script_index_by_name(name_to_slot_index_itemmap);
24165 80 }
24166
24167 ///----------------------------------------------------------------------------------------------------//
24168 //Tile Manipulation
24169
24170 49233554 void do_copytile(const bool v, const bool v2)
24171 {
24172 49233554 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24173 49233554 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24174
24175 49233554 copy_tile(newtilebuf, tile, tile2, false);
24176 49233554 }
24177
24178 int32_t FFScript::IsBlankTile(int32_t i)
24179 {
24180 if( ((unsigned)i) > NEWMAXTILES )
24181 {
24182 scripting_log_error_with_context("Invalid tile ID {}", i);
24183 return -1;
24184 }
24185
24186 byte *tilestart=newtilebuf[i].data;
24187 qword *di=(qword*)tilestart;
24188 int32_t parts=tilesize(newtilebuf[i].format)>>3;
24189
24190 for(int32_t j=0; j<parts; ++j, ++di)
24191 {
24192 if(*di!=0)
24193 {
24194 return 0;
24195 }
24196 }
24197
24198 return 1;
24199 }
24200
24201 int32_t FFScript::Is8BitTile(int32_t i)
24202 {
24203 if (((unsigned)i) > NEWMAXTILES)
24204 {
24205 scripting_log_error_with_context("Invalid tile ID {}", i);
24206 return -1;
24207 }
24208
24209 return newtilebuf[i].format == tf8Bit ? 1 : 0;
24210 }
24211
24212 void do_swaptile(const bool v, const bool v2)
24213 {
24214 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24215 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24216
24217 copy_tile(newtilebuf, tile, tile2, true);
24218 }
24219
24220 57032 void do_overlaytile(const bool v, const bool v2)
24221 {
24222 57032 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24223 57032 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24224
24225
2/4
✓ Branch 0 taken 57032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57032 times.
✗ Branch 3 not taken.
57032 if(BC::checkTile(tile) != SH::_NoError ||
24226 57032 BC::checkTile(tile2) != SH::_NoError)
24227 return;
24228
24229 //Could add an arg for the CSet or something instead of just passing 0, currently only 8-bit is supported
24230 57032 overlay_tile(newtilebuf, tile, tile2, 0, false);
24231 57032 }
24232
24233 void do_fliprotatetile(const bool v, const bool v2)
24234 {
24235 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24236 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24237
24238 if(BC::checkTile(tile) != SH::_NoError ||
24239 BC::checkTile(tile2) != SH::_NoError)
24240 return;
24241
24242 //fliprotatetile
24243 }
24244
24245 void do_settilepixel()
24246 {
24247 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
24248 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
24249 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
24250 int32_t val = SH::read_stack(ri->sp + 0) / 10000;
24251
24252 if(BC::checkTile(tile) != SH::_NoError)
24253 return;
24254
24255 x = vbound(x, 0, 15);
24256 y = vbound(y, 0, 15);
24257 unpack_tile(newtilebuf, tile, 0, false);
24258 if (newtilebuf[tile].format == tf4Bit)
24259 val &= 0xF;
24260 unpackbuf[y * 16 + x] = val;
24261 pack_tile(newtilebuf, unpackbuf, tile);
24262 }
24263
24264 void do_gettilepixel()
24265 {
24266 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
24267 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
24268 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
24269 int32_t cs = SH::read_stack(ri->sp + 0) / 10000;
24270
24271 if(BC::checkTile(tile) != SH::_NoError)
24272 return;
24273
24274 x = vbound(x, 0, 15);
24275 y = vbound(y, 0, 15);
24276 unpack_tile(newtilebuf, tile, 0, false);
24277 int32_t csoffs = newtilebuf[tile].format == tf8Bit ? 0 : cs * 16;
24278 ri->d[rEXP1] = 10000 * (unpackbuf[y * 16 + x] + csoffs);
24279 }
24280
24281 void do_shifttile(const bool v, const bool v2)
24282 {
24283 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24284 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24285
24286 if(BC::checkTile(tile) != SH::_NoError ||
24287 BC::checkTile(tile2) != SH::_NoError)
24288 return;
24289
24290 //shifttile
24291 }
24292
24293 10 void do_cleartile(const bool v)
24294 {
24295 10 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24296
24297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(BC::checkTile(tile) != SH::_NoError)
24298 return;
24299
24300 10 reset_tile(newtilebuf, tile, newtilebuf[tile].format);
24301 10 }
24302
24303 3062 void do_combotile(const bool v)
24304 {
24305 3062 int32_t combo = SH::get_arg(sarg2, v) / 10000;
24306
24307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3062 times.
3062 if(BC::checkCombo(combo) != SH::_NoError)
24308 return;
24309
24310 3062 set_register(sarg1, combobuf[combo].tile * 10000);
24311 3062 }
24312
24313 232889401 void do_readpod(const bool v)
24314 {
24315 232889401 int32_t indx = SH::get_arg(sarg2, v) / 10000;
24316 232889401 int32_t val = ArrayH::getElement(ri->d[rINDEX], indx, can_neg_array);
24317 232889401 set_register(sarg1, val);
24318 232889401 }
24319 134157907 void do_writepod(const bool v1, const bool v2)
24320 {
24321 134157907 int32_t indx = SH::get_arg(sarg1, v1) / 10000;
24322 134157907 int32_t val = SH::get_arg(sarg2, v2);
24323 134157907 ArrayH::setElement(ri->d[rINDEX], indx, val, can_neg_array);
24324 134157907 }
24325 3240508 void do_writepodstr()
24326 {
24327
2/2
✓ Branch 0 taken 30329 times.
✓ Branch 1 taken 3210179 times.
3240508 if(!sargstr) return;
24328 3210179 uint32_t id = get_register(sarg1);
24329 3210179 ArrayH::setArray(id, *sargstr);
24330 3240508 }
24331 560076 void do_writepodarr()
24332 {
24333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 560076 times.
560076 if(!sargvec) return;
24334
24335 560076 uint32_t id = get_register(sarg1);
24336 560076 ArrayH::setArray(id, sargvec->size(), sargvec->data(), false);
24337 560076 }
24338
24339 25 int32_t get_own_i(ScriptType type)
24340 {
24341
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
25 switch(type)
24342 {
24343 case ScriptType::Lwpn:
24344 return ri->lwpn;
24345 case ScriptType::Ewpn:
24346 return ri->ewpn;
24347 case ScriptType::ItemSprite:
24348 return ri->itemref;
24349 case ScriptType::NPC:
24350 25 return ri->guyref;
24351 case ScriptType::FFC:
24352 if (auto ffc = ResolveFFC(ri->ffcref))
24353 return ffc->index;
24354 }
24355 return 0;
24356 25 }
24357
24358 portal* loadportal(savedportal& p);
24359
24360 ///----------------------------------------------------------------------------------------------------//
24361 // Run the script //
24362 ///----------------------------------------------------------------------------------------------------//
24363
24364 703728643 static bool check_cmp(uint cmp)
24365 {
24366
2/2
✓ Branch 0 taken 32057 times.
✓ Branch 1 taken 703696586 times.
703728643 if(cmp & CMP_BOOL)
24367 {
24368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32057 times.
32057 if(ri->cmp_strcache) return false; //Cast string to bool? nonsense...
24369
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 32055 times.
32057 switch(cmp & CMP_FLAGS)
24370 {
24371 case CMP_EQ:
24372 2 return !ri->cmp_op1 == !ri->cmp_op2;
24373 case CMP_NE:
24374 32055 return !ri->cmp_op1 != !ri->cmp_op2;
24375 }
24376 return false;
24377 }
24378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 703696586 times.
703696586 else if(ri->cmp_strcache)
24379 {
24380 if(*ri->cmp_strcache < 0)
24381 return (cmp & CMP_LT);
24382 if(*ri->cmp_strcache > 0)
24383 return (cmp & CMP_GT);
24384 return (cmp & CMP_EQ);
24385 }
24386 else
24387 {
24388
2/2
✓ Branch 0 taken 326463074 times.
✓ Branch 1 taken 377233512 times.
703696586 if(cmp & CMP_GT)
24389
2/2
✓ Branch 0 taken 114678801 times.
✓ Branch 1 taken 262554711 times.
377233512 if(ri->cmp_op1 > ri->cmp_op2)
24390 114678801 return true;
24391
2/2
✓ Branch 0 taken 372464788 times.
✓ Branch 1 taken 216552997 times.
589017785 if(cmp & CMP_LT)
24392
2/2
✓ Branch 0 taken 70511178 times.
✓ Branch 1 taken 146041819 times.
216552997 if(ri->cmp_op1 < ri->cmp_op2)
24393 70511178 return true;
24394
2/2
✓ Branch 0 taken 117255678 times.
✓ Branch 1 taken 401250929 times.
518506607 if(cmp & CMP_EQ)
24395
2/2
✓ Branch 0 taken 150160127 times.
✓ Branch 1 taken 251090802 times.
401250929 if(ri->cmp_op1 == ri->cmp_op2)
24396 150160127 return true;
24397 368346480 return false;
24398 }
24399 703728643 }
24400
24401 4570 static void markRegisterType(int reg, int type)
24402 {
24403 // Currently only marking globals as objects is supported.
24404
1/2
✓ Branch 0 taken 4570 times.
✗ Branch 1 not taken.
4570 if (!(reg >= GD(0) && reg <= GD(MAX_SCRIPT_REGISTERS)))
24405 {
24406 assert(false);
24407 }
24408
1/2
✓ Branch 0 taken 4570 times.
✗ Branch 1 not taken.
4570 if (!(type >= 0 && type <= (int)script_object_type::last))
24409 {
24410 assert(false);
24411 }
24412
24413 4570 int index = reg - GD(0);
24414 4570 game->global_d_types[index] = (script_object_type)type;
24415 4570 }
24416
24417 1116 static void markGlobalRegisters()
24418 {
24419 word scommand;
24420 1116 auto& init_script = *globalscripts[GLOBAL_SCRIPT_INIT];
24421
2/2
✓ Branch 0 taken 651 times.
✓ Branch 1 taken 465 times.
1116 if (!init_script.valid())
24422 465 return;
24423
24424 651 auto& zasm = init_script.zasm_script->zasm;
24425 651 uint32_t start_pc = init_script.pc, end_pc = init_script.end_pc;
24426
24427
2/2
✓ Branch 0 taken 651 times.
✓ Branch 1 taken 515335 times.
515986 for (auto pc = start_pc; pc < end_pc; pc++)
24428 {
24429 515335 scommand = zasm[pc].command;
24430
2/2
✓ Branch 0 taken 512975 times.
✓ Branch 1 taken 2360 times.
515335 if(scommand == MARK_TYPE_REG)
24431 2360 markRegisterType(zasm[pc].arg1, zasm[pc].arg2);
24432 515335 }
24433 1116 }
24434
24435 void goto_err(char const* opname)
24436 {
24437 auto i = curScriptIndex;
24438 const char* type_str = ScriptTypeToString(curScriptType);
24439 switch(curScriptType)
24440 {
24441 case ScriptType::FFC:
24442 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ffcmap[i].scriptname.c_str(), opname, sarg1); break;
24443 case ScriptType::NPC:
24444 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, npcmap[i].scriptname.c_str(), opname, sarg1); break;
24445 case ScriptType::Lwpn:
24446 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, lwpnmap[i].scriptname.c_str(), opname, sarg1); break;
24447 case ScriptType::Ewpn:
24448 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ewpnmap[i].scriptname.c_str(), opname, sarg1); break;
24449 case ScriptType::ItemSprite:
24450 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemspritemap[i].scriptname.c_str(), opname, sarg1); break;
24451 case ScriptType::Item:
24452 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemmap[i].scriptname.c_str(), opname, sarg1); break;
24453 case ScriptType::Global:
24454 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, globalmap[i].scriptname.c_str(), opname, sarg1); break;
24455 case ScriptType::Hero:
24456 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, playermap[i].scriptname.c_str(), opname, sarg1); break;
24457 case ScriptType::Screen:
24458 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, screenmap[i].scriptname.c_str(), opname, sarg1); break;
24459 case ScriptType::OnMap:
24460 case ScriptType::DMap:
24461 case ScriptType::ScriptedActiveSubscreen:
24462 case ScriptType::ScriptedPassiveSubscreen:
24463 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, dmapmap[i].scriptname.c_str(), opname, sarg1); break;
24464 case ScriptType::Combo:
24465 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, comboscriptmap[i].scriptname.c_str(), opname, sarg1); break;
24466
24467 default: break;
24468 }
24469 }
24470
24471 85581 static void script_exit_cleanup(bool no_dealloc)
24472 {
24473 85581 ScriptType type = curScriptType;
24474 85581 word script = curScriptNum;
24475 85581 int32_t i = curScriptIndex;
24476
24477
7/8
✓ Branch 0 taken 10606 times.
✓ Branch 1 taken 62571 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10217 times.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 47 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 2049 times.
85581 switch(type)
24478 {
24479 case ScriptType::FFC:
24480 {
24481
1/2
✓ Branch 0 taken 10217 times.
✗ Branch 1 not taken.
10217 if (auto ffc = ResolveFFCWithID(i))
24482 10217 ffc->script = 0;
24483 10217 auto& data = get_script_engine_data(type, i);
24484 10217 data.doscript = false;
24485 10217 data.clear_ref();
24486 }
24487 10217 break;
24488
24489 case ScriptType::Screen:
24490 81 get_scr(i)->script = 0;
24491 case ScriptType::Global:
24492 case ScriptType::Hero:
24493 case ScriptType::DMap:
24494 case ScriptType::OnMap:
24495 case ScriptType::ScriptedActiveSubscreen:
24496 case ScriptType::ScriptedPassiveSubscreen:
24497 case ScriptType::EngineSubscreen:
24498 case ScriptType::Combo:
24499 {
24500 10687 auto& data = get_script_engine_data(type, i);
24501 10687 data.doscript = false;
24502 10687 data.clear_ref();
24503 }
24504 10687 break;
24505 case ScriptType::Ewpn:
24506 case ScriptType::Lwpn:
24507 case ScriptType::NPC:
24508 case ScriptType::ItemSprite:
24509 {
24510 62571 auto& data = get_script_engine_data(type, i);
24511 62571 data.doscript = false;
24512 62571 data.clear_ref();
24513
1/2
✓ Branch 0 taken 62571 times.
✗ Branch 1 not taken.
62571 if (auto spr = sprite::getByUID(i))
24514 62571 spr->script = 0;
24515 }
24516 62571 break;
24517
24518 case ScriptType::Generic:
24519 47 user_genscript::get(script).quit();
24520 47 break;
24521
24522 case ScriptType::GenericFrozen:
24523 {
24524 // TODO use `i`?
24525 10 auto& data = get_script_engine_data(type, gen_frozen_index-1);
24526 10 data.doscript = false;
24527 10 data.clear_ref();
24528 10 break;
24529 }
24530
24531 case ScriptType::Item:
24532 {
24533
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
24534 2049 auto& data = get_script_engine_data(type, i);
24535
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 if ( !collect )
24536 {
24537
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1742 if ( (itemsbuf[i].flags&item_passive_script) && game->item[i] ) itemsbuf[i].script = 0; //Quit perpetual scripts, too.
24538 1742 }
24539 2049 data.doscript = 0;
24540 2049 data.clear_ref();
24541 2049 break;
24542 }
24543 }
24544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85581 times.
85581 if(!no_dealloc)
24545
2/2
✓ Branch 0 taken 83532 times.
✓ Branch 1 taken 2049 times.
85581 switch(type)
24546 {
24547 case ScriptType::Item:
24548 {
24549
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
24550
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
2049 int new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
24551 2049 FFScript::deallocateAllScriptOwned(type, new_i);
24552 2049 break;
24553 }
24554
24555 default:
24556 83532 FFScript::deallocateAllScriptOwned(type, i);
24557 83532 break;
24558 85581 }
24559 85581 }
24560
24561 30564919 int32_t run_script(ScriptType type, word script, int32_t i)
24562 {
24563
3/4
✓ Branch 0 taken 30564919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 30564828 times.
30564919 if(Quit==qRESET || Quit==qEXIT) // In case an earlier script hung
24564 91 return RUNSCRIPT_ERROR;
24565
24566
4/4
✓ Branch 0 taken 19451509 times.
✓ Branch 1 taken 11113319 times.
✓ Branch 2 taken 3894668 times.
✓ Branch 3 taken 15556841 times.
30564828 if(type != ScriptType::Global && !script) return RUNSCRIPT_OK; //Safeguard against running null scripts
24567
24568 26670160 combopos_modified = -1;
24569 26670160 curScriptType=type;
24570 26670160 curScriptNum=script;
24571 26670160 curScriptIndex=i;
24572 26670160 current_zasm_register=0;
24573 //numInstructions=0; //DON'T CLEAR THIS OR IT CAN HARDLOCK! -Em
24574
24575
2/4
✓ Branch 0 taken 26670160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26670160 times.
26670160 if (!(type >= ScriptType::First && type <= ScriptType::Last))
24576 {
24577 al_trace("Invalid script type: %d\n", (int)type);
24578 return RUNSCRIPT_ERROR;
24579 }
24580
24581 26670160 auto& data = get_script_engine_data(type, i);
24582 26670160 bool got_initialized = set_current_script_engine_data(data, type, script, i);
24583
24584 // Because qst.cpp likes to write script_data without setting this.
24585 26670160 curscript->meta.script_type = type;
24586
24587 // If script isn't valid, we don't have a `pc` to start from... just exit.
24588
2/2
✓ Branch 0 taken 26667338 times.
✓ Branch 1 taken 2822 times.
26670160 if(!curscript->valid())
24589 {
24590 2822 script_exit_cleanup(false);
24591 2822 return RUNSCRIPT_OK;
24592 }
24593
24594 26667338 script_funcrun = false;
24595
24596 26667338 JittedScriptHandle* jitted_script = nullptr;
24597
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 26667334 times.
26667338 if (jit_is_enabled())
24598 {
24599 26667334 auto& data = get_script_engine_data(type, i);
24600
2/2
✓ Branch 0 taken 24021822 times.
✓ Branch 1 taken 2645512 times.
26667334 if (!data.jitted_script)
24601 2645512 data.jitted_script = std::shared_ptr<JittedScriptHandle>(jit_create_script_handle(curscript, ri, got_initialized));
24602 26667334 jitted_script = data.jitted_script.get();
24603 26667334 }
24604
24605 26667338 runtime_script_debug_handle = nullptr;
24606
1/2
✓ Branch 0 taken 26667338 times.
✗ Branch 1 not taken.
26667338 if (script_debug_is_runtime_debugging())
24607 {
24608 if (!script_debug_handles.contains(curscript->id))
24609 {
24610 script_debug_handles.emplace(curscript->id, ScriptDebugHandle(
24611 curscript->zasm_script.get(), ScriptDebugHandle::OutputSplit::ByFrame, curscript->name()));
24612 }
24613 runtime_script_debug_handle = &script_debug_handles.at(curscript->id);
24614 runtime_script_debug_handle->update_file();
24615 std::string line = fmt::format("=== running script type: {} index: {} name: {} i: {} script: {}", ScriptTypeToString(curscript->id.type), curscript->id.index, curscript->meta.script_name, i, script);
24616 runtime_script_debug_handle->print("\n");
24617 runtime_script_debug_handle->print(line.c_str());
24618 runtime_script_debug_handle->print("\n");
24619
24620 replay_step_comment(line);
24621 }
24622
1/2
✓ Branch 0 taken 26667338 times.
✗ Branch 1 not taken.
26667338 if (script_debug_is_runtime_debugging() == 1)
24623 {
24624 std::string line = script_debug_registers_and_stack_to_string();
24625 runtime_script_debug_handle->print(line.c_str());
24626 runtime_script_debug_handle->print("\n");
24627
24628 util::replchar(line, '\n', ' ');
24629 replay_step_comment(line);
24630 }
24631
24632 int32_t result;
24633
2/2
✓ Branch 0 taken 24110575 times.
✓ Branch 1 taken 2556763 times.
26667338 if (jitted_script)
24634 {
24635
2/2
✓ Branch 0 taken 29625 times.
✓ Branch 1 taken 24080950 times.
24110575 if (ri->waitframes)
24636 {
24637 29625 --ri->waitframes;
24638 29625 result = RUNSCRIPT_OK;
24639 29625 }
24640 else
24641 {
24642 // Retain the script handler because if deleted while running, terrible things can happen (crash),
24643 // as the jit runtimes often write to it. Typically a script won't delete its own script handle,
24644 // but scripts can run nested, so lets capture a temporary retaining reference as part of the
24645 // call stack.
24646 24080950 auto retainer = data.jitted_script;
24647
1/2
✓ Branch 0 taken 24080950 times.
✗ Branch 1 not taken.
24080950 result = jit_run_script(jitted_script);
24648
24649
4/4
✓ Branch 0 taken 24080949 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 24080948 times.
24080950 if (result == RUNSCRIPT_JIT_STACK_OVERFLOW || result == RUNSCRIPT_JIT_CALL_LIMIT)
24650 {
24651 2 ri->overflow = true;
24652
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (result == RUNSCRIPT_JIT_STACK_OVERFLOW)
24653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 log_stack_overflow_error();
24654 else
24655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 log_call_limit_error();
24656
24657
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (!(script_funcrun && curscript->meta.ffscript_v < 23))
24658 {
24659
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 script_exit_cleanup(false);
24660 2 result = RUNSCRIPT_STOPPED;
24661 2 }
24662 else
24663 {
24664 result = RUNSCRIPT_OK;
24665 }
24666 2 }
24667 24080950 }
24668 24110575 }
24669 else
24670 {
24671 2556763 result = run_script_int(false);
24672 }
24673
24674
2/2
✓ Branch 0 taken 24306354 times.
✓ Branch 1 taken 2360984 times.
26667338 if (ZScriptVersion::gc())
24675 {
24676 // Drain the autorelease pool.
24677 // Move the vector, since destructors can possibly
24678 // create objects and modify `script_object_autorelease_pool`.
24679 2360984 auto ids = std::move(script_object_autorelease_pool);
24680
2/2
✓ Branch 0 taken 2360984 times.
✓ Branch 1 taken 37121 times.
2398105 for (auto id : ids)
24681
1/2
✓ Branch 0 taken 37121 times.
✗ Branch 1 not taken.
37121 script_object_ref_dec(id);
24682
24683 // This throttles the actual full GC run.
24684
1/2
✓ Branch 0 taken 2360984 times.
✗ Branch 1 not taken.
2360984 maybe_run_gc();
24685 2360984 }
24686
24687
6/16
✗ Branch 0 not taken.
✓ Branch 1 taken 26667338 times.
✓ Branch 2 taken 26667338 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26667338 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 26667338 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 26667338 times.
✓ Branch 10 taken 26667338 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
53334676 if (replay_is_active() && replay_get_meta_bool("debug_script_state"))
24688 {
24689 std::string str = script_debug_registers_and_stack_to_string();
24690 util::replstr(str, "\n", " ");
24691 replay_step_comment(str);
24692 }
24693
24694
1/2
✓ Branch 0 taken 26667338 times.
✗ Branch 1 not taken.
26667338 if (runtime_script_debug_handle)
24695 {
24696 runtime_script_debug_handle->print(fmt::format("result: {}\n", result).c_str());
24697 replay_step_comment(fmt::format("result: {}", result));
24698 }
24699 26667338 return result;
24700 30564919 }
24701
24702 1074110259 int32_t run_script_int(bool is_jitted)
24703 {
24704 1074110259 ScriptType type = curScriptType;
24705 1074110259 word script = curScriptNum;
24706 1074110259 int32_t i = curScriptIndex;
24707
24708 1074110259 current_zasm_command=(ASM_DEFINE)0; // this is actually SETV, but we never will print that as a context string, so it's fine.
24709
24710 1074110259 int commands_run = 0;
24711 1074110259 int jit_waiting_nop = false;
24712
2/2
✓ Branch 0 taken 1074109449 times.
✓ Branch 1 taken 810 times.
1074110259 bool old_script_funcrun = script_funcrun && curscript->meta.ffscript_v < 23;
24713
2/2
✓ Branch 0 taken 1071552686 times.
✓ Branch 1 taken 2557573 times.
1074110259 if(!is_jitted)
24714 {
24715
2/2
✓ Branch 0 taken 543 times.
✓ Branch 1 taken 2557030 times.
2557573 if(ri->waitframes)
24716 {
24717 543 --ri->waitframes;
24718 543 return RUNSCRIPT_OK;
24719 }
24720 2557030 zs_vargs.clear();
24721
24722 #ifdef _FFDISSASSEMBLY
24723
24724 if(curscript->zasm[ri->pc].command != 0xFFFF)
24725 {
24726 #ifdef _FFONESCRIPTDISSASSEMBLY
24727 zc_trace_clear();
24728 #endif
24729
24730 switch(type)
24731 {
24732 case ScriptType::FFC:
24733 al_trace("\nStart of FFC script %i processing on FFC %i:\n", script, i);
24734 break;
24735
24736 case ScriptType::Item:
24737 al_trace("\nStart of item script %i processing:\n", script);
24738 break;
24739
24740 case ScriptType::Global:
24741 al_trace("\nStart of global script %I processing:\n", script);
24742 break;
24743 }
24744 }
24745
24746 #endif
24747 2557030 }
24748 //j_command
24749 1074109716 bool is_debugging = script_debug_is_runtime_debugging() == 2;
24750 1074109716 bool increment = true;
24751
5/8
✓ Branch 0 taken 227 times.
✓ Branch 1 taken 1074109489 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 227 times.
✓ Branch 4 taken 227 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 227 times.
✗ Branch 7 not taken.
1074109716 static std::vector<ffscript> empty_zasm = {{0xFFFF}};
24752
1/2
✓ Branch 0 taken 1074109716 times.
✗ Branch 1 not taken.
1074109716 const auto& zasm = curscript->valid() ? curscript->zasm_script->zasm : empty_zasm;
24753 1074109716 word scommand = zasm[ri->pc].command;
24754 1074109716 bool hit_invalid_zasm = false;
24755 1074109716 bool no_dealloc = false;
24756
2/2
✓ Branch 0 taken 9820 times.
✓ Branch 1 taken 10147166986 times.
10147176806 while(scommand != 0xFFFF)
24757 {
24758 10147166986 const auto& op = zasm[ri->pc];
24759 10147166986 scommand = op.command;
24760 10147166986 sarg1 = op.arg1;
24761 10147166986 sarg2 = op.arg2;
24762 10147166986 sarg3 = op.arg3;
24763 10147166986 sargstr = op.strptr;
24764 10147166986 sargvec = op.vecptr;
24765
24766 10147166986 current_zasm_command = (ASM_DEFINE)op.command;
24767
24768
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 10147166986 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
10147166986 if (is_debugging && (!is_jitted || commands_run > 0))
24769 {
24770 runtime_script_debug_handle->pre_command();
24771 }
24772
24773 10147166986 bool waiting = true;
24774
6/6
✓ Branch 0 taken 10120611902 times.
✓ Branch 1 taken 6048440 times.
✓ Branch 2 taken 977482 times.
✓ Branch 3 taken 3138 times.
✓ Branch 4 taken 19523977 times.
✓ Branch 5 taken 2047 times.
10147166986 switch(scommand) //Handle waitframe-type commands first
24775 {
24776 case WAITDRAW:
24777 {
24778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6048440 times.
6048440 if(script_funcrun)
24779 scommand = NOP;
24780
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 6048440 times.
✗ Branch 2 not taken.
6048440 else switch(type)
24781 {
24782 case ScriptType::EngineSubscreen: //ignore waitdraws
24783 Z_scripterrlog("'Waitdraw()' is invalid in subscreen scripts, will be ignored\n");
24784 scommand = NOP;
24785 break;
24786 case ScriptType::Generic:
24787 case ScriptType::GenericFrozen: //ignore waitdraws
24788 Z_scripterrlog("'Waitdraw()' is invalid in generic scripts, will be ignored\n");
24789 scommand = NOP;
24790 break;
24791 }
24792 6048440 break;
24793 }
24794 case WAITTO:
24795 {
24796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(script_funcrun)
24797 scommand = NOP;
24798
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 977482 times.
977482 else switch(type)
24799 {
24800 case ScriptType::GenericFrozen:
24801 //ignore, no warn/error
24802 scommand = NOP;
24803 break;
24804 case ScriptType::Generic:
24805 {
24806 977482 user_genscript& scr = user_genscript::get(script);
24807 977482 int32_t target = get_register(sarg1)/10000L;
24808 977482 bool atleast = get_register(sarg2)!=0;
24809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(unsigned(target) > SCR_TIMING_END_FRAME)
24810 {
24811 Z_scripterrlog("Invalid value '%d' provided to 'WaitTo()'\n", target);
24812 scommand = NOP;
24813 break;
24814 }
24815
2/4
✓ Branch 0 taken 977481 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
977482 if(genscript_timing == target ||
24816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977481 times.
977481 (atleast && genscript_timing < target))
24817 {
24818 //Already that time, skip the command
24819 1 scommand = NOP;
24820 1 break;
24821 }
24822 977481 scr.waituntil = scr_timing(target);
24823 977481 scr.wait_atleast = atleast;
24824 977481 break;
24825 }
24826 default:
24827 Z_scripterrlog("'WaitTo()' is only valid in 'generic' scripts!\n");
24828 scommand = NOP;
24829 break;
24830 }
24831 977482 break;
24832 }
24833 case WAITEVENT:
24834 {
24835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3138 times.
3138 if(script_funcrun)
24836 scommand = NOP;
24837
1/3
✓ Branch 0 taken 3138 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
3138 else switch(type)
24838 {
24839 case ScriptType::GenericFrozen:
24840 scommand = WAITFRAME;
24841 ri->d[0] = GENSCR_EVENT_NIL*10000; //no event
24842 break;
24843 case ScriptType::Generic:
24844 {
24845 3138 user_genscript& scr = user_genscript::get(script);
24846 3138 scr.waitevent = true;
24847 3138 break;
24848 }
24849 default:
24850 Z_scripterrlog("'WaitEvent()' is only valid in 'generic' scripts!\n");
24851 scommand = NOP;
24852 break;
24853 }
24854 3138 break;
24855 }
24856 case WAITFRAME:
24857 {
24858
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19523977 times.
19523977 if(script_funcrun)
24859 scommand = NOP;
24860
2/2
✓ Branch 0 taken 18365697 times.
✓ Branch 1 taken 1158280 times.
19523977 else switch(type)
24861 {
24862 case ScriptType::Generic:
24863 {
24864 1158280 user_genscript& scr = user_genscript::get(script);
24865 1158280 scr.waituntil = SCR_TIMING_START_FRAME;
24866 1158280 scr.wait_atleast = false;
24867 1158280 break;
24868 }
24869 }
24870 19523977 break;
24871 }
24872 case WAITFRAMESR:
24873 {
24874 2047 auto count = get_register(sarg1);
24875
3/4
✓ Branch 0 taken 2047 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 690 times.
✓ Branch 3 taken 1357 times.
2047 if(script_funcrun || count <= 0)
24876 {
24877 690 scommand = NOP;
24878 690 break;
24879 }
24880 1357 auto frames = count/10000;
24881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1357 times.
1357 if(count%10000) ++frames; //round up decimals
24882 1357 ri->waitframes = frames-1; //this frame doesn't count
24883
2/2
✓ Branch 0 taken 1054 times.
✓ Branch 1 taken 303 times.
1357 switch(type)
24884 {
24885 case ScriptType::Generic:
24886 {
24887 303 user_genscript& scr = user_genscript::get(script);
24888 303 scr.waituntil = SCR_TIMING_START_FRAME;
24889 303 scr.wait_atleast = false;
24890 303 break;
24891 }
24892 }
24893 1357 break;
24894 }
24895 10120611902 default: waiting = false;
24896 10120611902 }
24897
4/4
✓ Branch 0 taken 26555084 times.
✓ Branch 1 taken 10120611902 times.
✓ Branch 2 taken 26554393 times.
✓ Branch 3 taken 691 times.
10147166986 if(waiting && scommand != NOP)
24898 {
24899
2/2
✓ Branch 0 taken 2547231 times.
✓ Branch 1 taken 24007162 times.
26554393 if (is_jitted)
24900 24007162 jit_waiting_nop = true;
24901 26554393 break;
24902 }
24903
24904 10120612593 numInstructions++;
24905
2/2
✓ Branch 0 taken 10110492067 times.
✓ Branch 1 taken 10120526 times.
10120612593 if(numInstructions==hangcount) // No need to check frequently
24906 {
24907 10120526 numInstructions=0;
24908 10120526 poll_keyboard();
24909 10120526 checkQuitKeys();
24910
2/2
✓ Branch 0 taken 10120524 times.
✓ Branch 1 taken 2 times.
10120526 if(Quit)
24911 2 scommand=0xFFFF;
24912 10120526 }
24913
24914
266/880
✓ Branch 0 taken 82675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1268285141 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1236034762 times.
✓ Branch 6 taken 44520347 times.
✓ Branch 7 taken 360205 times.
✓ Branch 8 taken 50 times.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 466370 times.
✓ Branch 11 taken 2400 times.
✓ Branch 12 taken 13768103 times.
✓ Branch 13 taken 5 times.
✓ Branch 14 taken 10 times.
✓ Branch 15 taken 10105627 times.
✓ Branch 16 taken 753675 times.
✓ Branch 17 taken 23926879 times.
✓ Branch 18 taken 18341 times.
✓ Branch 19 taken 1721259 times.
✓ Branch 20 taken 26763741 times.
✓ Branch 21 taken 5062724 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✓ Branch 24 taken 138537 times.
✓ Branch 25 taken 6352 times.
✓ Branch 26 taken 17821 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✓ Branch 32 taken 1707 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 31 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✓ Branch 40 taken 53727 times.
✓ Branch 41 taken 5 times.
✓ Branch 42 taken 1649950 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 15 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 10089782 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 969 times.
✓ Branch 52 taken 1289847 times.
✓ Branch 53 taken 8299299 times.
✓ Branch 54 taken 678025 times.
✓ Branch 55 taken 243283 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✓ Branch 58 taken 4677945 times.
✓ Branch 59 taken 34306 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 3 times.
✓ Branch 65 taken 1383 times.
✓ Branch 66 taken 287 times.
✓ Branch 67 taken 11645 times.
✓ Branch 68 taken 33588 times.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 178 times.
✓ Branch 73 taken 3783 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 1117 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 585769 times.
✓ Branch 82 taken 5620654 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 85 taken 432438 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✓ Branch 88 taken 16 times.
✓ Branch 89 taken 223 times.
✓ Branch 90 taken 11 times.
✓ Branch 91 taken 87 times.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✓ Branch 108 taken 1205956 times.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✓ Branch 112 taken 208946 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✓ Branch 115 taken 5 times.
✓ Branch 116 taken 3 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 50 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 3062 times.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✓ Branch 126 taken 10 times.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✓ Branch 134 taken 440764 times.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✓ Branch 216 taken 3 times.
✓ Branch 217 taken 5 times.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✓ Branch 221 taken 6877 times.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✓ Branch 224 taken 1 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 279 times.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✓ Branch 236 taken 6 times.
✓ Branch 237 taken 8 times.
✓ Branch 238 taken 10 times.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✓ Branch 244 taken 76234 times.
✓ Branch 245 taken 67629 times.
✓ Branch 246 taken 2210 times.
✓ Branch 247 taken 4 times.
✓ Branch 248 taken 22 times.
✓ Branch 249 taken 53639074 times.
✓ Branch 250 taken 45321201 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 8301 times.
✓ Branch 253 taken 1665452 times.
✓ Branch 254 taken 2 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 1936805764 times.
✓ Branch 257 taken 101072668 times.
✓ Branch 258 taken 8 times.
✓ Branch 259 taken 1639541 times.
✓ Branch 260 taken 535 times.
✓ Branch 261 taken 262182 times.
✗ Branch 262 not taken.
✓ Branch 263 taken 297440888 times.
✓ Branch 264 taken 31597255 times.
✓ Branch 265 taken 209313780 times.
✓ Branch 266 taken 209294241 times.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✓ Branch 269 taken 117775060 times.
✓ Branch 270 taken 120987694 times.
✓ Branch 271 taken 99811587 times.
✓ Branch 272 taken 32806172 times.
✓ Branch 273 taken 694501 times.
✓ Branch 274 taken 44313 times.
✓ Branch 275 taken 355595 times.
✓ Branch 276 taken 6704 times.
✓ Branch 277 taken 151435325 times.
✓ Branch 278 taken 81454076 times.
✓ Branch 279 taken 50481970 times.
✗ Branch 280 not taken.
✓ Branch 281 taken 80747026 times.
✓ Branch 282 taken 2928911 times.
✓ Branch 283 taken 3240508 times.
✓ Branch 284 taken 560076 times.
✗ Branch 285 not taken.
✓ Branch 286 taken 374507859 times.
✗ Branch 287 not taken.
✓ Branch 288 taken 297914197 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 467135544 times.
✓ Branch 291 taken 628111557 times.
✓ Branch 292 taken 124597239 times.
✓ Branch 293 taken 69310 times.
✓ Branch 294 taken 306616 times.
✓ Branch 295 taken 11869542 times.
✗ Branch 296 not taken.
✓ Branch 297 taken 858818435 times.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✓ Branch 300 taken 140979711 times.
✓ Branch 301 taken 45159 times.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✓ Branch 306 taken 13656663 times.
✗ Branch 307 not taken.
✓ Branch 308 taken 303069082 times.
✓ Branch 309 taken 80 times.
✓ Branch 310 taken 3358336 times.
✗ Branch 311 not taken.
✓ Branch 312 taken 4378083 times.
✓ Branch 313 taken 66250575 times.
✓ Branch 314 taken 158191929 times.
✓ Branch 315 taken 21244502 times.
✓ Branch 316 taken 91949 times.
✗ Branch 317 not taken.
✓ Branch 318 taken 949760 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 4377267 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 9550421 times.
✓ Branch 323 taken 6483138 times.
✓ Branch 324 taken 100 times.
✓ Branch 325 taken 1480 times.
✓ Branch 326 taken 6050 times.
✓ Branch 327 taken 14918 times.
✗ Branch 328 not taken.
✓ Branch 329 taken 5879938 times.
✓ Branch 330 taken 37547 times.
✗ Branch 331 not taken.
✓ Branch 332 taken 499288 times.
✓ Branch 333 taken 16 times.
✓ Branch 334 taken 2541 times.
✗ Branch 335 not taken.
✓ Branch 336 taken 2925 times.
✓ Branch 337 taken 2 times.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✓ Branch 346 taken 14 times.
✓ Branch 347 taken 4797 times.
✓ Branch 348 taken 56 times.
✓ Branch 349 taken 935 times.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 357 not taken.
✓ Branch 358 taken 1 times.
✗ Branch 359 not taken.
✓ Branch 360 taken 1664 times.
✓ Branch 361 taken 137117 times.
✓ Branch 362 taken 105 times.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✓ Branch 366 taken 2394272 times.
✓ Branch 367 taken 176378 times.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✓ Branch 371 taken 2397 times.
✓ Branch 372 taken 1520226 times.
✓ Branch 373 taken 140585 times.
✓ Branch 374 taken 30 times.
✓ Branch 375 taken 1731287 times.
✓ Branch 376 taken 2674 times.
✓ Branch 377 taken 2912197 times.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✓ Branch 382 taken 6556 times.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✓ Branch 388 taken 648 times.
✓ Branch 389 taken 40410211 times.
✓ Branch 390 taken 1106752 times.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✓ Branch 395 taken 3709786 times.
✓ Branch 396 taken 73964923 times.
✓ Branch 397 taken 2752254 times.
✓ Branch 398 taken 26716589 times.
✓ Branch 399 taken 10744 times.
✓ Branch 400 taken 17 times.
✗ Branch 401 not taken.
✗ Branch 402 not taken.
✓ Branch 403 taken 22 times.
✗ Branch 404 not taken.
✓ Branch 405 taken 34296 times.
✗ Branch 406 not taken.
✓ Branch 407 taken 12533 times.
✗ Branch 408 not taken.
✓ Branch 409 taken 34 times.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 417 not taken.
✓ Branch 418 taken 22 times.
✓ Branch 419 taken 2 times.
✓ Branch 420 taken 319 times.
✗ Branch 421 not taken.
✓ Branch 422 taken 15 times.
✓ Branch 423 taken 3 times.
✗ Branch 424 not taken.
✓ Branch 425 taken 107 times.
✗ Branch 426 not taken.
✓ Branch 427 taken 127 times.
✗ Branch 428 not taken.
✓ Branch 429 taken 5660 times.
✗ Branch 430 not taken.
✓ Branch 431 taken 5436 times.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✓ Branch 434 taken 339164 times.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✓ Branch 437 taken 2004 times.
✗ Branch 438 not taken.
✓ Branch 439 taken 63829 times.
✗ Branch 440 not taken.
✓ Branch 441 taken 236 times.
✓ Branch 442 taken 140 times.
✓ Branch 443 taken 1 times.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✓ Branch 448 taken 14 times.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✓ Branch 453 taken 2768 times.
✓ Branch 454 taken 1452537 times.
✓ Branch 455 taken 4712412 times.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✓ Branch 460 taken 6365 times.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✓ Branch 463 taken 3209679 times.
✓ Branch 464 taken 177544 times.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✓ Branch 467 taken 10 times.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✓ Branch 472 taken 11 times.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✓ Branch 475 taken 24 times.
✓ Branch 476 taken 92 times.
✗ Branch 477 not taken.
✓ Branch 478 taken 370 times.
✗ Branch 479 not taken.
✓ Branch 480 taken 31 times.
✗ Branch 481 not taken.
✓ Branch 482 taken 1064 times.
✓ Branch 483 taken 130 times.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✗ Branch 488 not taken.
✓ Branch 489 taken 450 times.
✓ Branch 490 taken 4781 times.
✗ Branch 491 not taken.
✓ Branch 492 taken 112 times.
✓ Branch 493 taken 234 times.
✗ Branch 494 not taken.
✓ Branch 495 taken 931 times.
✓ Branch 496 taken 53 times.
✗ Branch 497 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✓ Branch 505 taken 24 times.
✓ Branch 506 taken 24 times.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✓ Branch 510 taken 12 times.
✓ Branch 511 taken 598 times.
✓ Branch 512 taken 27870027 times.
✓ Branch 513 taken 87669 times.
✗ Branch 514 not taken.
✓ Branch 515 taken 209493 times.
✗ Branch 516 not taken.
✓ Branch 517 taken 22444 times.
✓ Branch 518 taken 3530 times.
✗ Branch 519 not taken.
✓ Branch 520 taken 587 times.
✓ Branch 521 taken 31487 times.
✓ Branch 522 taken 5 times.
✓ Branch 523 taken 43 times.
✓ Branch 524 taken 11754119 times.
✓ Branch 525 taken 160009 times.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✓ Branch 528 taken 19653 times.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✓ Branch 531 taken 21032557 times.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✓ Branch 534 taken 257 times.
✓ Branch 535 taken 354943 times.
✓ Branch 536 taken 354990 times.
✓ Branch 537 taken 3 times.
✓ Branch 538 taken 13670631 times.
✓ Branch 539 taken 18282859 times.
✓ Branch 540 taken 357 times.
✓ Branch 541 taken 118 times.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✓ Branch 547 taken 26528 times.
✓ Branch 548 taken 3512 times.
✓ Branch 549 taken 146 times.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✓ Branch 559 taken 49233554 times.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✓ Branch 563 taken 57032 times.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✓ Branch 571 taken 7069332 times.
✓ Branch 572 taken 4 times.
✓ Branch 573 taken 38 times.
✓ Branch 574 taken 9 times.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✓ Branch 577 taken 2 times.
✗ Branch 578 not taken.
✓ Branch 579 taken 30 times.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✓ Branch 593 taken 3560 times.
✓ Branch 594 taken 66 times.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✓ Branch 604 taken 92 times.
✗ Branch 605 not taken.
✓ Branch 606 taken 1798 times.
✓ Branch 607 taken 3596 times.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 620 not taken.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✗ Branch 625 not taken.
✗ Branch 626 not taken.
✗ Branch 627 not taken.
✓ Branch 628 taken 15 times.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✗ Branch 698 not taken.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 707 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✗ Branch 719 not taken.
✗ Branch 720 not taken.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✗ Branch 724 not taken.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✓ Branch 806 taken 10 times.
✓ Branch 807 taken 46 times.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✓ Branch 818 taken 291091 times.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✓ Branch 821 taken 1 times.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✓ Branch 825 taken 1 times.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✓ Branch 829 taken 1 times.
✓ Branch 830 taken 1 times.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✓ Branch 851 taken 1338 times.
✓ Branch 852 taken 448056 times.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✓ Branch 856 taken 73 times.
✗ Branch 857 not taken.
✓ Branch 858 taken 137117 times.
✗ Branch 859 not taken.
✓ Branch 860 taken 14870 times.
✓ Branch 861 taken 17877 times.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✓ Branch 866 taken 828 times.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✓ Branch 873 taken 30120 times.
✗ Branch 874 not taken.
✓ Branch 875 taken 1374 times.
✓ Branch 876 taken 30120 times.
✓ Branch 877 taken 95901 times.
✓ Branch 878 taken 226 times.
✓ Branch 879 taken 1654 times.
10120612593 switch(scommand)
24915 {
24916 //always first
24917 case 0xFFFF: //invalid command
24918 {
24919 2 const char* type_str = ScriptTypeToString(type);
24920
2/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
2 switch(type)
24921 {
24922 case ScriptType::FFC:
24923 1 zprint("%s Script %s has exited.\n", type_str, ffcmap[i].scriptname.c_str()); break;
24924 case ScriptType::NPC:
24925 zprint("%s Script %s has exited.\n", type_str, npcmap[i].scriptname.c_str()); break;
24926 case ScriptType::Lwpn:
24927 zprint("%s Script %s has exited.\n", type_str, lwpnmap[i].scriptname.c_str()); break;
24928 case ScriptType::Ewpn:
24929 zprint("%s Script %s has exited.\n", type_str, ewpnmap[i].scriptname.c_str()); break;
24930 case ScriptType::ItemSprite:
24931 zprint("%s Script %s has exited.\n", type_str, itemspritemap[i].scriptname.c_str()); break;
24932 case ScriptType::Item:
24933 zprint("%s Script %s has exited.\n", type_str, itemmap[i].scriptname.c_str()); break;
24934 case ScriptType::Global:
24935 1 zprint("%s Script %s has exited.\n", type_str, globalmap[i].scriptname.c_str()); break;
24936 case ScriptType::Hero:
24937 zprint("%s Script %s has exited.\n", type_str, playermap[i].scriptname.c_str()); break;
24938 case ScriptType::Screen:
24939 zprint("%s Script %s has exited.\n", type_str, screenmap[i].scriptname.c_str()); break;
24940 case ScriptType::OnMap:
24941 case ScriptType::DMap:
24942 case ScriptType::ScriptedActiveSubscreen:
24943 case ScriptType::ScriptedPassiveSubscreen:
24944 zprint("%s Script %s has exited.\n", type_str, dmapmap[i].scriptname.c_str()); break;
24945 case ScriptType::Combo: zprint("%s Script %s has exited.\n", type_str, comboscriptmap[i].scriptname.c_str()); break;
24946
24947 default: break;
24948 }
24949 2 break;
24950 }
24951 case QUIT:
24952 82675 scommand = 0xFFFF;
24953 82675 break;
24954 case QUIT_NO_DEALLOC:
24955 scommand = 0xFFFF;
24956 no_dealloc = true;
24957 break;
24958
24959 case NOP: //No Operation. Do nothing. -Em
24960 {
24961 // While we are here, skip many NOPs in a row to avoid the overhead
24962 // of the interpreter loop. This is especially good for how `zasm_optimize`
24963 // works, since it replaces many commands with a sequence of NOPs.
24964 // No need to do a bounds check - the last command should always be 0xFFFF.
24965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1936805764 times.
1936805764 if (is_debugging)
24966 break;
24967
2/2
✓ Branch 0 taken 2188258501 times.
✓ Branch 1 taken 1936805764 times.
4125064265 while (zasm[ri->pc + 1].command == NOP)
24968 2188258501 ri->pc++;
24969 1936805764 break;
24970 }
24971 case GOTO:
24972 {
24973
1/2
✓ Branch 0 taken 101072668 times.
✗ Branch 1 not taken.
101072668 if(sarg1 < 0 )
24974 {
24975 goto_err("GOTO");
24976 scommand = 0xFFFF;
24977 break;
24978 }
24979 101072668 ri->pc = sarg1;
24980 101072668 increment = false;
24981 101072668 break;
24982 }
24983 case GOTOR:
24984 {
24985
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(sarg1 < 0 )
24986 {
24987 goto_err("GOTOR");
24988 scommand = 0xFFFF;
24989 break;
24990 }
24991 8 ri->pc = (get_register(sarg1) / 10000) - 1;
24992 8 increment = false;
24993 }
24994 8 break;
24995
24996 case GOTOTRUE:
24997
2/2
✓ Branch 0 taken 1368320 times.
✓ Branch 1 taken 271221 times.
1639541 if(check_cmp(CMP_EQ))
24998 {
24999
1/2
✓ Branch 0 taken 271221 times.
✗ Branch 1 not taken.
271221 if(sarg1 < 0 )
25000 {
25001 goto_err("GOTOTRUE");
25002 scommand = 0xFFFF;
25003 break;
25004 }
25005 271221 ri->pc = sarg1;
25006 271221 increment = false;
25007 271221 }
25008 1639541 break;
25009
25010 case GOTOFALSE:
25011
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 235 times.
535 if(check_cmp(CMP_NE))
25012 {
25013
1/2
✓ Branch 0 taken 235 times.
✗ Branch 1 not taken.
235 if(sarg1 < 0 )
25014 {
25015 goto_err("GOTOFALSE");
25016 scommand = 0xFFFF;
25017 break;
25018 }
25019 235 ri->pc = sarg1;
25020 235 increment = false;
25021 235 }
25022 535 break;
25023
25024 case GOTOMORE:
25025
2/2
✓ Branch 0 taken 239253 times.
✓ Branch 1 taken 22929 times.
262182 if(check_cmp(CMP_GE))
25026 {
25027
1/2
✓ Branch 0 taken 22929 times.
✗ Branch 1 not taken.
22929 if(sarg1 < 0 )
25028 {
25029 goto_err("GOTOMORE");
25030 scommand = 0xFFFF;
25031 break;
25032 }
25033 22929 ri->pc = sarg1;
25034 22929 increment = false;
25035 22929 }
25036 262182 break;
25037
25038 case GOTOLESS:
25039 if(check_cmp(get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LT : CMP_LE))
25040 {
25041 if(sarg1 < 0 )
25042 {
25043 goto_err("GOTOLESS");
25044 scommand = 0xFFFF;
25045 break;
25046 }
25047 ri->pc = sarg1;
25048 increment = false;
25049 }
25050 break;
25051
25052 case GOTOCMP:
25053 {
25054 297440888 bool run = check_cmp(sarg2);
25055
2/2
✓ Branch 0 taken 104654301 times.
✓ Branch 1 taken 192786587 times.
297440888 if(run)
25056 {
25057
1/2
✓ Branch 0 taken 192786587 times.
✗ Branch 1 not taken.
192786587 if(sarg1 < 0 )
25058 {
25059 goto_err("GOTOCMP");
25060 scommand = 0xFFFF;
25061 break;
25062 }
25063 192786587 ri->pc = sarg1;
25064 192786587 increment = false;
25065 192786587 }
25066 297440888 break;
25067 }
25068
25069 case SETCMP:
25070 {
25071 31597255 bool run = check_cmp(sarg2);
25072
2/2
✓ Branch 0 taken 30007810 times.
✓ Branch 1 taken 1589445 times.
31597255 set_register(sarg1, run ? ((sarg2 & CMP_SETI) ? 10000 : 1) : 0);
25073 31597255 break;
25074 }
25075
25076 case CALLFUNC:
25077 {
25078 209313780 retstack_push(ri->pc+1);
25079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209313780 times.
209313780 if(sarg1 < 0 )
25080 {
25081 goto_err("CALLFUNC");
25082 scommand = 0xFFFF;
25083 break;
25084 }
25085 209313780 ri->pc = sarg1;
25086 209313780 increment = false;
25087 209313780 break;
25088 }
25089 case RETURNFUNC:
25090 {
25091
2/2
✓ Branch 0 taken 209293431 times.
✓ Branch 1 taken 810 times.
209294241 if(auto retpc = retstack_pop())
25092 {
25093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209293431 times.
209293431 if(*retpc < 0)
25094 {
25095 goto_err("RETURNFUNC");
25096 scommand = 0xFFFF;
25097 break;
25098 }
25099 209293431 ri->pc = *retpc;
25100 209293431 increment = false;
25101 209293431 }
25102 else //Returned from 'void run()', QUIT
25103 {
25104 810 scommand = 0xFFFF;
25105 }
25106 209294241 break;
25107 }
25108
25109 case LOOP:
25110 {
25111 if(get_register(sarg2) > 0)
25112 {
25113 ri->pc = sarg1;
25114 increment = false;
25115 }
25116 else
25117 {
25118 set_register(sarg1, sarg1 - 1);
25119 }
25120 }
25121 break;
25122
25123 case RETURN:
25124 {
25125 if (script_funcrun)
25126 break; //handled below, poorly. 'RETURNFUNC' does this better now.
25127 ri->pc = SH::read_stack(ri->sp) - 1;
25128 ++ri->sp;
25129 increment = false;
25130 break;
25131 }
25132
25133 case SETTRUE:
25134 117775060 set_register(sarg1, check_cmp(CMP_EQ) ? 1 : 0);
25135 117775060 break;
25136
25137 case SETFALSE:
25138 120987694 set_register(sarg1, check_cmp(CMP_NE) ? 1 : 0);
25139 120987694 break;
25140
25141 case SETMORE:
25142 99811587 set_register(sarg1, check_cmp(CMP_GE) ? 1 : 0);
25143 99811587 break;
25144
25145 case SETLESS:
25146 32806172 set_register(sarg1, check_cmp(CMP_LE) ? 1 : 0);
25147 32806172 break;
25148
25149 case SETTRUEI:
25150 694501 set_register(sarg1, check_cmp(CMP_EQ) ? 10000 : 0);
25151 694501 break;
25152
25153 case SETFALSEI:
25154 44313 set_register(sarg1, check_cmp(CMP_NE) ? 10000 : 0);
25155 44313 break;
25156
25157 case SETMOREI:
25158 355595 set_register(sarg1, check_cmp(CMP_GE) ? 10000 : 0);
25159 355595 break;
25160
25161 case SETLESSI:
25162 6704 set_register(sarg1, check_cmp(CMP_LE) ? 10000 : 0);
25163 6704 break;
25164
25165 case READPODARRAYR:
25166 {
25167 151435325 do_readpod(false);
25168 151435325 break;
25169 }
25170 case READPODARRAYV:
25171 {
25172 81454076 do_readpod(true);
25173 81454076 break;
25174 }
25175 case WRITEPODARRAYRR:
25176 {
25177 50481970 do_writepod(false,false);
25178 50481970 break;
25179 }
25180 case WRITEPODARRAYRV:
25181 {
25182 do_writepod(false,true);
25183 break;
25184 }
25185 case WRITEPODARRAYVR:
25186 {
25187 80747026 do_writepod(true,false);
25188 80747026 break;
25189 }
25190 case WRITEPODARRAYVV:
25191 {
25192 2928911 do_writepod(true,true);
25193 2928911 break;
25194 }
25195 case WRITEPODSTRING:
25196 {
25197 3240508 do_writepodstr();
25198 3240508 break;
25199 }
25200 case WRITEPODARRAY:
25201 {
25202 560076 do_writepodarr();
25203 560076 break;
25204 }
25205
25206 case NOT:
25207 do_not(false);
25208 break;
25209
25210 case COMPAREV:
25211 374507859 do_comp(true);
25212 374507859 break;
25213 case COMPAREV2:
25214 do_comp(true,true);
25215 break;
25216
25217 case COMPARER:
25218 297914197 do_comp(false);
25219 297914197 break;
25220
25221 case STRCMPR:
25222 do_internal_strcmp();
25223 break;
25224
25225 case STRICMPR:
25226 do_internal_stricmp();
25227 break;
25228
25229 case SETV:
25230 467135544 do_set_command(true);
25231 467135544 break;
25232
25233 case SETR:
25234 628111557 do_set_command(false);
25235 628111557 break;
25236
25237 case PUSHR:
25238 1268285141 do_push(false);
25239 1268285141 break;
25240
25241 case PUSHV:
25242 124597239 do_push(true);
25243 124597239 break;
25244
25245 case PEEK:
25246 69310 do_peek();
25247 69310 break;
25248 case PEEKATV:
25249 do_peekat(true);
25250 break;
25251 case STACKWRITEATRV:
25252 do_writeat(false, true);
25253 break;
25254 case STACKWRITEATVV_IF:
25255
2/2
✓ Branch 0 taken 90545 times.
✓ Branch 1 taken 216071 times.
306616 if(!check_cmp(sarg3))
25256 216071 break;
25257 [[fallthrough]];
25258 case STACKWRITEATVV:
25259 98846 do_writeat(true, true);
25260 98846 break;
25261 case POP:
25262 1236034762 do_pop();
25263 1236034762 break;
25264
25265 case POPARGS:
25266 44520347 do_pops();
25267 44520347 break;
25268
25269 case PUSHARGSR:
25270 11869542 do_pushs(false);
25271 11869542 break;
25272
25273 case PUSHARGSV:
25274 360205 do_pushs(true);
25275 360205 break;
25276
25277 case LOADI:
25278 50 do_loadi();
25279 50 break;
25280
25281 case STOREI:
25282 8 do_storei();
25283 8 break;
25284
25285 case LOADD:
25286 do_loadd();
25287 break;
25288
25289 case LOAD:
25290 858818435 do_load();
25291 858818435 break;
25292
25293 case STORED:
25294 do_stored(false);
25295 break;
25296 case STOREDV:
25297 do_stored(true);
25298 break;
25299 case STORE:
25300 140979711 do_store(false);
25301 140979711 break;
25302 case STOREV:
25303 466370 do_store(true);
25304 466370 break;
25305 case STORE_OBJECT:
25306 45159 do_store_object(false);
25307 45159 break;
25308
25309 // Note: this was never used.
25310 case ALLOCATEGMEMR:
25311 if(type == ScriptType::Global) do_allocatemem(false, false, type, i);
25312
25313 break;
25314
25315 case ALLOCATEGMEMV:
25316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2400 times.
2400 if(type == ScriptType::Global) do_allocatemem(true, false, type, i);
25317
25318 2400 break;
25319
25320 case ALLOCATEMEMR:
25321 do_allocatemem(false, true, type, i);
25322 break;
25323
25324 case ALLOCATEMEMV:
25325 13768103 do_allocatemem(true, true, type, i);
25326 13768103 break;
25327
25328 case RESIZEARRAYR:
25329 5 do_resize_array();
25330 5 break;
25331 case OWNARRAYR:
25332 do_own_array(get_register(sarg1), type, i);
25333 break;
25334 case DESTROYARRAYR:
25335 do_destroy_array();
25336 break;
25337
25338 // Pre-3.0, the compiler inserted this command for every local array at the end of it scope.
25339 case DEALLOCATEMEMR:
25340 13656663 do_deallocatemem();
25341 13656663 break;
25342
25343 case SAVEGAMESTRUCTS:
25344 10 using_SRAM = 1;
25345 10 FFCore.do_savegamestructs(false,false);
25346 10 using_SRAM = 0;
25347 10 break;
25348 case READGAMESTRUCTS:
25349 using_SRAM = 1;
25350 FFCore.do_loadgamestructs(false,false);
25351 using_SRAM = 0;
25352 break;
25353 case ARRAYSIZE:
25354 303069082 do_arraysize();
25355 303069082 break;
25356
25357 case GETFFCSCRIPT:
25358 10105627 do_getffcscript();
25359 10105627 break;
25360 case GETITEMSCRIPT:
25361 80 do_getitemscript();
25362 80 break;
25363
25364 case LOAD_FFC:
25365 {
25366
1/2
✓ Branch 0 taken 3358336 times.
✗ Branch 1 not taken.
3358336 if (!ZScriptVersion::ffcRefIsSpriteId())
25367 {
25368 set_register(sarg1, get_register(sarg1) - 10000);
25369 break;
25370 }
25371
25372 3358336 int ffc_id = get_register(sarg1) / 10000 - 1;
25373
1/2
✓ Branch 0 taken 3358336 times.
✗ Branch 1 not taken.
3358336 if (auto ffc = ResolveFFCWithID(ffc_id))
25374 3358336 set_register(sarg1, ffc->getUID());
25375 else
25376 set_register(sarg1, 0);
25377 3358336 break;
25378 }
25379
25380 case LOAD_FFC_2:
25381 {
25382 if (!ZScriptVersion::ffcRefIsSpriteId())
25383 {
25384 set_register(sarg1, get_register(sarg2) - 10000);
25385 break;
25386 }
25387
25388 int screen = get_register(sarg1) / 10000;
25389 int index = get_register(sarg2) / 10000;
25390
25391 if (!is_in_current_region(screen))
25392 {
25393 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
25394 break;
25395 }
25396 if (BC::checkMapdataFFC(index) != SH::_NoError)
25397 break;
25398
25399 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + index;
25400 if (auto ffc = ResolveFFCWithID(ffc_id))
25401 set_register(sarg1, ffc->getUID());
25402 else
25403 set_register(sarg1, 0);
25404
25405 break;
25406 }
25407
25408 case CASTBOOLI:
25409 753675 do_boolcast(false);
25410 753675 break;
25411
25412 case CASTBOOLF:
25413 4378083 do_boolcast(true);
25414 4378083 break;
25415
25416 case ADDV:
25417 66250575 do_add(true);
25418 66250575 break;
25419
25420 case ADDR:
25421 158191929 do_add(false);
25422 158191929 break;
25423
25424 case SUBV:
25425 23926879 do_sub(true);
25426 23926879 break;
25427 case SUBV2:
25428 18341 do_sub(true,true);
25429 18341 break;
25430
25431 case SUBR:
25432 21244502 do_sub(false);
25433 21244502 break;
25434
25435 case MULTV:
25436 1721259 do_mult(true);
25437 1721259 break;
25438
25439 case MULTR:
25440 26763741 do_mult(false);
25441 26763741 break;
25442
25443 case DIVV:
25444 91949 do_div(true);
25445 91949 break;
25446 case DIVV2:
25447 do_div(true,true);
25448 break;
25449
25450 case DIVR:
25451 5062724 do_div(false);
25452 5062724 break;
25453
25454 case MODV:
25455 949760 do_mod(true);
25456 949760 break;
25457 case MODV2:
25458 do_mod(true,true);
25459 break;
25460
25461 case MODR:
25462 4377267 do_mod(false);
25463 4377267 break;
25464
25465 case SINV:
25466 do_trig(true, 0);
25467 break;
25468
25469 case SINR:
25470 9550421 do_trig(false, 0);
25471 9550421 break;
25472
25473 case COSV:
25474 do_trig(true, 1);
25475 break;
25476
25477 case COSR:
25478 6483138 do_trig(false, 1);
25479 6483138 break;
25480
25481 case TANV:
25482 do_trig(true, 2);
25483 break;
25484
25485 case TANR:
25486 100 do_trig(false, 2);
25487 100 break;
25488
25489 case DEGTORAD:
25490 1480 do_degtorad();
25491 1480 break;
25492
25493 case RADTODEG:
25494 138537 do_radtodeg();
25495 138537 break;
25496
25497 case STRINGLENGTH:
25498 6050 FFCore.do_strlen(false);
25499 6050 break;
25500
25501 case ARCSINR:
25502 14918 do_asin(false);
25503 14918 break;
25504
25505 case ARCCOSR:
25506 do_acos(false);
25507 break;
25508
25509 case ARCTANR:
25510 5879938 do_arctan();
25511 5879938 break;
25512
25513 //Text ptr functions
25514 case FONTHEIGHTR:
25515 6352 do_fontheight();
25516 6352 break;
25517 case STRINGWIDTHR:
25518 17821 do_strwidth();
25519 17821 break;
25520 case CHARWIDTHR:
25521 37547 do_charwidth();
25522 37547 break;
25523 case MESSAGEWIDTHR:
25524 ri->d[rEXP1] = 10000* do_msgwidth(get_register(sarg1)/10000);
25525 break;
25526 case MESSAGEHEIGHTR:
25527 ri->d[rEXP1] = 10000* do_msgheight(get_register(sarg1)/10000);
25528 break;
25529 //
25530
25531 case COMBO_AT:
25532 {
25533 499288 int32_t x = get_register(sarg1) / 10000;
25534 499288 int32_t y = get_register(sarg2) / 10000;
25535 499288 x = std::clamp(x, 0, world_w - 1);
25536 499288 y = std::clamp(y, 0, world_h - 1);
25537 499288 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
25538 499288 break;
25539 }
25540
25541 case COMBO_ADJUST:
25542 {
25543 16 rpos_t rpos = (rpos_t)(get_register(sarg1) / 10000);
25544
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (!is_valid_rpos(rpos))
25545 {
25546 set_register(sarg1, -1);
25547 break;
25548 }
25549
25550 144 auto [x, y] = COMBOXY_REGION(rpos);
25551 32 x += get_register(sarg2) / 10000;
25552 32 y += get_register(sarg3) / 10000;
25553 32 x = std::clamp(x, 0, world_w - 1);
25554 32 y = std::clamp(y, 0, world_h - 1);
25555 48 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
25556 16 break;
25557 }
25558
25559 //String.h functions 2.55 Alpha 23
25560 2541 case STRINGCOMPARE: FFCore.do_strcmp(); break;
25561 case STRINGICOMPARE: FFCore.do_stricmp(); break;
25562 2925 case STRINGCOPY: FFCore.do_strcpy(false,false); break;
25563 2 case ARRAYCOPY: FFCore.do_arraycpy(false,false); break;
25564 case STRINGNCOMPARE: FFCore.do_strncmp(); break;
25565 case STRINGNICOMPARE: FFCore.do_strnicmp(); break;
25566
25567 //More string.h functions, 19th May, 2019
25568 case XLEN: FFCore.do_xlen(false); break;
25569 case XTOI: FFCore.do_xtoi(false); break;
25570 case ILEN: FFCore.do_ilen(false); break;
25571 case ATOI: FFCore.do_atoi(false); break;
25572 case ATOL: FFCore.do_atol(false); break;
25573 case STRCSPN: FFCore.do_strcspn(); break;
25574 case STRSTR: FFCore.do_strstr(); break;
25575 14 case XTOA: FFCore.do_xtoa(); break;
25576 4797 case ITOA: FFCore.do_itoa(); break;
25577 56 case ITOACAT: FFCore.do_itoacat(); break;
25578 935 case STRCAT: FFCore.do_strcat(); break;
25579 case STRSPN: FFCore.do_strspn(); break;
25580 case STRCHR: FFCore.do_strchr(); break;
25581 case STRRCHR: FFCore.do_strrchr(); break;
25582 case XLEN2: FFCore.do_xlen2(); break;
25583 case XTOI2: FFCore.do_xtoi2(); break;
25584 case ILEN2: FFCore.do_ilen2(); break;
25585 case ATOI2: FFCore.do_atoi2(); break;
25586 case REMCHR2: FFCore.do_remchr2(); break;
25587 case UPPERTOLOWER: FFCore.do_UpperToLower(false); break;
25588 1 case LOWERTOUPPER: FFCore.do_LowerToUpper(false); break;
25589 case CONVERTCASE: FFCore.do_ConvertCase(false); break;
25590
25591 case GETNPCSCRIPT: FFCore.do_getnpcscript(); break;
25592 case GETCOMBOSCRIPT: FFCore.do_getcomboscript(); break;
25593 1707 case GETLWEAPONSCRIPT: FFCore.do_getlweaponscript(); break;
25594 1664 case GETEWEAPONSCRIPT: FFCore.do_geteweaponscript(); break;
25595 case GETHEROSCRIPT: FFCore.do_getheroscript(); break;
25596 137117 case GETGENERICSCRIPT: FFCore.do_getgenericscript(); break;
25597 case GETGLOBALSCRIPT: FFCore.do_getglobalscript(); break;
25598 105 case GETDMAPSCRIPT: FFCore.do_getdmapscript(); break;
25599 case GETSCREENSCRIPT: FFCore.do_getscreenscript(); break;
25600 31 case GETSPRITESCRIPT: FFCore.do_getitemspritescript(); break;
25601 case GETUNTYPEDSCRIPT: FFCore.do_getuntypedscript(); break;
25602 case GETSUBSCREENSCRIPT:FFCore.do_getsubscreenscript(); break;
25603 case GETNPCBYNAME: FFCore.do_getnpcbyname(); break;
25604 case GETITEMBYNAME: FFCore.do_getitembyname(); break;
25605 case GETCOMBOBYNAME: FFCore.do_getcombobyname(); break;
25606 case GETDMAPBYNAME: FFCore.do_getdmapbyname(); break;
25607
25608 case ABS:
25609 2394272 do_abs(false);
25610 2394272 break;
25611
25612 case MINR:
25613 176378 do_min(false);
25614 176378 break;
25615
25616 case MINV:
25617 do_min(true);
25618 break;
25619
25620 case MAXR:
25621 53727 do_max(false);
25622 53727 break;
25623 case MAXV:
25624 do_max(true);
25625 break;
25626 case WRAPRADIANS:
25627 do_wrap_rad(false);
25628 break;
25629 case WRAPDEGREES:
25630 2397 do_wrap_deg(false);
25631 2397 break;
25632
25633 case MAXVARG:
25634 1520226 FFCore.do_varg_max();
25635 1520226 break;
25636 case MINVARG:
25637 140585 FFCore.do_varg_min();
25638 140585 break;
25639 case CHOOSEVARG:
25640 5 FFCore.do_varg_choose();
25641 5 break;
25642 case MAKEVARGARRAY:
25643
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 assert(sarg1 >= 0 && sarg1 <= (int)script_object_type::last);
25644 30 FFCore.do_varg_makearray(type, i, (script_object_type)sarg1);
25645 30 break;
25646
25647 case PUSHVARGV:
25648 1649950 do_push_varg(true);
25649 1649950 break;
25650 case PUSHVARGR:
25651 1731287 do_push_varg(false);
25652 1731287 break;
25653 case PUSHVARGSV:
25654 2674 do_push_vargs(true);
25655 2674 break;
25656 case PUSHVARGSR:
25657 do_push_vargs(false);
25658 break;
25659
25660 case RNDR:
25661 2912197 do_rnd(false);
25662 2912197 break;
25663
25664 case RNDV:
25665 do_rnd(true);
25666 break;
25667
25668 case SRNDR:
25669 do_srnd(false);
25670 break;
25671
25672 case SRNDV:
25673 do_srnd(true);
25674 break;
25675
25676 case SRNDRND:
25677 do_srndrnd();
25678 break;
25679
25680 case GETRTCTIMER:
25681 15 FFCore.getRTC(false);
25682 15 break;
25683 case GETRTCTIMEV:
25684 FFCore.getRTC(true);
25685 break;
25686
25687 case FACTORIAL:
25688 do_factorial(false);
25689 break;
25690
25691 case SQROOTV:
25692 do_sqroot(true);
25693 break;
25694
25695 case SQROOTR:
25696 10089782 do_sqroot(false);
25697 10089782 break;
25698
25699 case POWERR:
25700 6556 do_power(false);
25701 6556 break;
25702 case POWERV:
25703 do_power(true);
25704 break;
25705 case POWERV2:
25706 do_power(true,true);
25707 break;
25708
25709 case LPOWERR:
25710 do_lpower(false);
25711 break;
25712 case LPOWERV:
25713 do_lpower(true);
25714 break;
25715 case LPOWERV2:
25716 do_lpower(true,true);
25717 break;
25718
25719 case IPOWERR:
25720 do_ipower(false);
25721 break;
25722
25723 case IPOWERV:
25724 do_ipower(true);
25725 break;
25726
25727 case LOG10:
25728 969 do_log10(false);
25729 969 break;
25730
25731 case LOGE:
25732 648 do_naturallog(false);
25733 648 break;
25734
25735 case ANDR:
25736 40410211 do_and(false);
25737 40410211 break;
25738
25739 case ANDV:
25740 1289847 do_and(true);
25741 1289847 break;
25742
25743 case ORR:
25744 8299299 do_or(false);
25745 8299299 break;
25746
25747 case ORV:
25748 1106752 do_or(true);
25749 1106752 break;
25750
25751 case XORR:
25752 678025 do_xor(false);
25753 678025 break;
25754
25755 case XORV:
25756 243283 do_xor(true);
25757 243283 break;
25758
25759 case NANDR:
25760 do_nand(false);
25761 break;
25762
25763 case NANDV:
25764 do_nand(true);
25765 break;
25766
25767 case NORR:
25768 do_nor(false);
25769 break;
25770
25771 case NORV:
25772 do_nor(true);
25773 break;
25774
25775 case XNORR:
25776 do_xnor(false);
25777 break;
25778
25779 case XNORV:
25780 do_xnor(true);
25781 break;
25782
25783 case BITNOT:
25784 3709786 do_bitwisenot(false);
25785 3709786 break;
25786
25787 case LSHIFTR:
25788 73964923 do_lshift(false);
25789 73964923 break;
25790
25791 case LSHIFTV:
25792 2752254 do_lshift(true);
25793 2752254 break;
25794
25795 case RSHIFTR:
25796 26716589 do_rshift(false);
25797 26716589 break;
25798
25799 case RSHIFTV:
25800 4677945 do_rshift(true);
25801 4677945 break;
25802
25803 case ANDR32:
25804 34306 do_and32(false);
25805 34306 break;
25806
25807 case ANDV32:
25808 10744 do_and32(true);
25809 10744 break;
25810
25811 case ORR32:
25812 17 do_or32(false);
25813 17 break;
25814
25815 case ORV32:
25816 do_or32(true);
25817 break;
25818
25819 case XORR32:
25820 do_xor32(false);
25821 break;
25822
25823 case XORV32:
25824 do_xor32(true);
25825 break;
25826
25827 case BITNOT32:
25828 do_bitwisenot32(false);
25829 break;
25830
25831 case LSHIFTR32:
25832 22 do_lshift32(false);
25833 22 break;
25834
25835 case LSHIFTV32:
25836 do_lshift32(true);
25837 break;
25838
25839 case RSHIFTR32:
25840 34296 do_rshift32(false);
25841 34296 break;
25842
25843 case RSHIFTV32:
25844 do_rshift32(true);
25845 break;
25846
25847 case TRACER:
25848 12533 FFCore.do_trace(false);
25849 12533 break;
25850
25851 case TRACELR:
25852 FFCore.do_tracel(false);
25853 break;
25854
25855 case TRACEV:
25856 34 FFCore.do_trace(true);
25857 34 break;
25858
25859 case TRACE2R:
25860 FFCore.do_tracebool(false);
25861 break;
25862
25863 //Zap and Wavy Effects
25864 case FXWAVYR:
25865 FFCore.do_fx_wavy(false);
25866 break;
25867 case FXZAPR:
25868 FFCore.do_fx_zap(false);
25869 break;
25870 //Zap and Wavy Effects
25871 case FXWAVYV:
25872 FFCore.do_fx_wavy(true);
25873 break;
25874 case FXZAPV:
25875 FFCore.do_fx_zap(true);
25876 break;
25877 case GREYSCALER:
25878 FFCore.do_greyscale(false);
25879 break;
25880 case GREYSCALEV:
25881 FFCore.do_greyscale(true);
25882 break;
25883 case MONOCHROMER:
25884 FFCore.do_monochromatic(false);
25885 break;
25886 case MONOCHROMEV:
25887 FFCore.do_monochromatic(true);
25888 break;
25889
25890 case TRACE2V:
25891 FFCore.do_tracebool(true);
25892 break;
25893
25894 case TRACE3:
25895 22 FFCore.do_tracenl();
25896 22 break;
25897
25898 case TRACE4:
25899 2 FFCore.do_cleartrace();
25900 2 break;
25901
25902 case TRACE5:
25903 3 FFCore.do_tracetobase();
25904 3 break;
25905
25906 case TRACE6:
25907 1383 FFCore.do_tracestring();
25908 1383 break;
25909
25910 case PRINTFV:
25911 287 FFCore.do_printf(true, false);
25912 287 break;
25913 case SPRINTFV:
25914 11645 FFCore.do_sprintf(true, false);
25915 11645 break;
25916
25917 case PRINTFVARG:
25918 33588 FFCore.do_printf(true, true);
25919 33588 break;
25920 case SPRINTFVARG:
25921 319 FFCore.do_sprintf(true, true);
25922 319 break;
25923 case PRINTFA:
25924 FFCore.do_printfarr();
25925 break;
25926 case SPRINTFA:
25927 FFCore.do_sprintfarr();
25928 break;
25929 case ARRAYPUSH:
25930 {
25931 15 auto ptr = SH::read_stack(ri->sp + 2);
25932 15 auto val = SH::read_stack(ri->sp + 1);
25933 15 auto indx = SH::read_stack(ri->sp + 0) / 10000;
25934 15 ArrayManager am(ptr);
25935 15 ri->d[rEXP1] = am.push(val,indx) ? 10000 : 0;
25936 15 break;
25937 }
25938 case ARRAYPOP:
25939 {
25940 3 auto ptr = SH::read_stack(ri->sp + 1);
25941 3 auto indx = SH::read_stack(ri->sp + 0) / 10000;
25942 3 ArrayManager am(ptr);
25943 3 ri->d[rEXP1] = am.pop(indx);
25944 3 break;
25945 }
25946
25947 case BREAKPOINT:
25948 FFCore.do_breakpoint();
25949 break;
25950
25951 case WARP:
25952 do_warp(true);
25953 break;
25954
25955 case WARPR:
25956 107 do_warp(false);
25957 107 break;
25958
25959 case PITWARP:
25960 do_pitwarp(true);
25961 break;
25962
25963 case PITWARPR:
25964 127 do_pitwarp(false);
25965 127 break;
25966
25967 case SELECTAWPNV:
25968 do_selectweapon(true, 1);
25969 break;
25970
25971 case SELECTAWPNR:
25972 5660 do_selectweapon(false, 1);
25973 5660 break;
25974
25975 case SELECTBWPNV:
25976 do_selectweapon(true, 0);
25977 break;
25978
25979 case SELECTBWPNR:
25980 5436 do_selectweapon(false, 0);
25981 5436 break;
25982
25983 case SELECTXWPNR:
25984 do_selectweapon(false, 2);
25985 break;
25986
25987 case SELECTYWPNR:
25988 do_selectweapon(false, 3);
25989 break;
25990
25991 case PLAYSOUNDR:
25992 339164 do_sfx(false);
25993 339164 break;
25994
25995 case PLAYSOUNDV:
25996 do_sfx(true);
25997 break;
25998
25999 case ADJUSTSFXVOLUMER: FFCore.do_adjustsfxvolume(false); break;
26000 case ADJUSTSFXVOLUMEV: FFCore.do_adjustsfxvolume(true); break;
26001 2004 case ADJUSTVOLUMER: FFCore.do_adjustvolume(false); break;
26002 case ADJUSTVOLUMEV: FFCore.do_adjustvolume(true); break;
26003
26004 case PLAYMIDIR:
26005 63829 do_midi(false);
26006 63829 break;
26007
26008 case PLAYMIDIV:
26009 do_midi(true);
26010 break;
26011
26012 case PLAYENHMUSIC:
26013 178 do_enh_music(false);
26014 178 break;
26015
26016 case GETMUSICFILE:
26017 236 do_get_enh_music_filename(false);
26018 236 break;
26019
26020 case GETMUSICTRACK:
26021 140 do_get_enh_music_track(false);
26022 140 break;
26023
26024 case SETDMAPENHMUSIC:
26025 3783 do_set_dmap_enh_music(false);
26026 3783 break;
26027
26028 // Audio->
26029
26030 case ENDSOUNDR:
26031 1 stop_sfx(false);
26032 1 break;
26033
26034 case ENDSOUNDV:
26035 stop_sfx(true);
26036 break;
26037
26038 case PAUSESOUNDR:
26039 pause_sfx(false);
26040 break;
26041
26042 case PAUSESOUNDV:
26043 pause_sfx(true);
26044 break;
26045
26046 case RESUMESOUNDR:
26047 resume_sfx(false);
26048 break;
26049
26050 case RESUMESOUNDV:
26051 resume_sfx(true);
26052 break;
26053
26054
26055
26056 case PAUSESFX:
26057 {
26058 int32_t sound = ri->d[rINDEX]/10000;
26059 pause_sfx(sound);
26060
26061 }
26062 break;
26063
26064 case RESUMESFX:
26065 {
26066 int32_t sound = ri->d[rINDEX]/10000;
26067 resume_sfx(sound);
26068 }
26069 break;
26070
26071 case ADJUSTSFX:
26072 {
26073 do_sfx_ex(false);
26074 }
26075 break;
26076
26077 case PLAYSOUNDEX:
26078 {
26079 14 do_sfx_ex(true);
26080 }
26081 14 break;
26082
26083 case GETSFXCOMPLETION:
26084 {
26085 do_get_sfx_completion();
26086 }
26087 break;
26088
26089 case CONTINUESFX:
26090 {
26091 int32_t sound = ri->d[rINDEX]/10000;
26092 //Backend::sfx->cont_sfx(sound);
26093
26094 //! cont_sfx was not ported to the new back end!!!
26095 // I believe this restarted the loop.
26096 resume_sfx(sound);
26097 //What was the old instruction, again? Did it exist? -Z
26098 //continue_sfx(sound);
26099 }
26100 break;
26101
26102
26103 /*
26104 case STOPITEMSOUND:
26105 void stop_item_sfx(int32_t family)
26106 */
26107
26108 // Note: these have never worked.
26109 case PAUSEMUSIC:
26110 //What was the instruction prior to adding backends?
26111 //! The pauseAll() function pauses sfx, not music, so this instruction is not doing what I intended. -Z
26112 //Check AllOff() -Z
26113 //zcmusic_pause(ZCMUSIC* zcm, int32_t pause); is in zcmusic.h
26114 // midi_paused = true;
26115 //pause_all_sfx();
26116
26117 //Backend::sfx->pauseAll();
26118 break;
26119 case RESUMEMUSIC:
26120 //What was the instruction prior to adding backends?
26121 //Check AllOff() -Z
26122 //resume_all_sfx();
26123 // midi_paused = false;
26124 //Backend::sfx->resumeAll();
26125 break;
26126
26127 case MSGSTRR:
26128 1117 do_message(false);
26129 1117 break;
26130
26131 case MSGSTRV:
26132 do_message(true);
26133 break;
26134
26135 case ITEMNAME:
26136 2768 do_getitemname();
26137 2768 break;
26138
26139 case LOADLWEAPONR:
26140 1452537 do_loadlweapon(false);
26141 1452537 break;
26142
26143 case LOADLWEAPONV:
26144 do_loadlweapon(true);
26145 break;
26146
26147 case LOADEWEAPONR:
26148 4712412 do_loadeweapon(false);
26149 4712412 break;
26150
26151 case LOADEWEAPONV:
26152 do_loadeweapon(true);
26153 break;
26154
26155 case LOADITEMR:
26156 585769 do_loaditem(false);
26157 585769 break;
26158
26159 case LOADITEMV:
26160 do_loaditem(true);
26161 break;
26162
26163 case LOADITEMDATAR:
26164 5620654 do_loaditemdata(false);
26165 5620654 break;
26166
26167 //New Datatypes
26168 case LOADSHOPR:
26169 FFScript::do_loadshopdata(false);
26170 break;
26171 case LOADSHOPV:
26172 FFScript::do_loadshopdata(true);
26173 break;
26174
26175 case LOADINFOSHOPR:
26176 FFScript::do_loadinfoshopdata(false);
26177 break;
26178 case LOADINFOSHOPV:
26179 FFScript::do_loadinfoshopdata(true);
26180 break;
26181 case LOADNPCDATAR:
26182 6365 FFScript::do_loadnpcdata(false);
26183 6365 break;
26184 case LOADNPCDATAV:
26185 FFScript::do_loadnpcdata(true);
26186 break;
26187
26188 case LOADCOMBODATAR:
26189 432438 FFScript::do_loadcombodata(false);
26190 432438 break;
26191 case LOADCOMBODATAV:
26192 FFScript::do_loadcombodata(true);
26193 break;
26194
26195 case LOADTMPSCR:
26196 3209679 FFScript::do_loadmapdata_tempscr(false);
26197 3209679 break;
26198 case LOADTMPSCR2:
26199 FFScript::do_loadmapdata_tempscr2(false);
26200 break;
26201 case REGION_LOAD_TMPSCR_FOR_LAYER_COMBO_POS:
26202 do_loadtmpscrforcombopos(false);
26203 break;
26204 case LOADSCROLLSCR:
26205 177544 FFScript::do_loadmapdata_scrollscr(false);
26206 177544 break;
26207 case LOADSCROLLSCR2:
26208 FFScript::do_loadmapdata_scrollscr2(false);
26209 break;
26210
26211 case LOADSPRITEDATAR:
26212 16 FFScript::do_loadspritedata(false);
26213 16 break;
26214 case LOADSPRITEDATAV:
26215 FFScript::do_loadspritedata(true);
26216 break;
26217
26218 case LOADBITMAPDATAR:
26219 10 FFScript::do_loadbitmapid(false);
26220 10 break;
26221
26222
26223 case LOADBITMAPDATAV:
26224 FFScript::do_loadbitmapid(true);
26225 break;
26226
26227 //functions
26228 case LOADDIRECTORYR:
26229 FFCore.do_loaddirectory(); break;
26230 case CREATEPALDATA:
26231 223 FFCore.do_create_paldata(); break;
26232 case CREATEPALDATACLR:
26233 11 FFCore.do_create_paldata_clr(); break;
26234 case MIXCLR:
26235 FFCore.do_mix_clr(); break;
26236 case CREATERGBHEX:
26237 FFCore.do_create_rgb_hex(); break;
26238 case CREATERGB:
26239 11 FFCore.do_create_rgb(); break;
26240 case CONVERTFROMRGB:
26241 FFCore.do_convert_from_rgb(); break;
26242 case CONVERTTORGB:
26243 FFCore.do_convert_to_rgb(); break;
26244 case PALDATALOADLEVEL:
26245 24 FFCore.do_paldata_load_level(); break;
26246 case PALDATALOADSPRITE:
26247 87 FFCore.do_paldata_load_sprite(); break;
26248 case PALDATALOADMAIN:
26249 92 FFCore.do_paldata_load_main(); break;
26250 case PALDATALOADCYCLE:
26251 FFCore.do_paldata_load_cycle(); break;
26252 case PALDATALOADBITMAP:
26253 FFCore.do_paldata_load_bitmap(); break;
26254 case PALDATAWRITELEVEL:
26255 370 FFCore.do_paldata_write_level(); break;
26256 case PALDATAWRITELEVELCS:
26257 FFCore.do_paldata_write_levelcset(); break;
26258 case PALDATAWRITESPRITE:
26259 31 FFCore.do_paldata_write_sprite(); break;
26260 case PALDATAWRITESPRITECS:
26261 FFCore.do_paldata_write_spritecset(); break;
26262 case PALDATAWRITEMAIN:
26263 1064 FFCore.do_paldata_write_main(); break;
26264 case PALDATAWRITEMAINCS:
26265 130 FFCore.do_paldata_write_maincset(); break;
26266 case PALDATAWRITECYCLE:
26267 FFCore.do_paldata_write_cycle(); break;
26268 case PALDATAWRITECYCLECS:
26269 FFCore.do_paldata_write_cyclecset(); break;
26270 case PALDATAVALIDCLR:
26271 FFCore.do_paldata_colorvalid(); break;
26272 case PALDATACLEARCLR:
26273 FFCore.do_paldata_clearcolor(); break;
26274 case PALDATACLEARCSET:
26275 FFCore.do_paldata_clearcset(); break;
26276 case PALDATAMIX:
26277 450 FFCore.do_paldata_mix(); break;
26278 case PALDATAMIXCS:
26279 4781 FFCore.do_paldata_mixcset(); break;
26280 case PALDATACOPY:
26281 FFCore.do_paldata_copy(); break;
26282 case PALDATACOPYCSET:
26283 112 FFCore.do_paldata_copycset(); break;
26284 case PALDATAFREE:
26285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (user_paldata* pd = checkPalData(ri->paldataref, true))
26286 {
26287 234 free_script_object(pd->id);
26288 234 }
26289 234 break;
26290 case PALDATAOWN:
26291 if (user_paldata* pd = checkPalData(ri->paldataref, false))
26292 {
26293 own_script_object(pd, type, i);
26294 }
26295 break;
26296 case LOADRNG: //command
26297 931 FFCore.do_loadrng(); break;
26298
26299 case ITEMGETDISPLAYNAME: //command
26300 53 item_display_name(false); break;
26301 case ITEMSETDISPLAYNAME: //command
26302 item_display_name(true); break;
26303 case ITEMGETSHOWNNAME: //command
26304 item_shown_name(); break;
26305
26306 case DMAPDATAGETNAMER: //command
26307 FFScript::do_getDMapData_dmapname(false); break;
26308 case DMAPDATAGETNAMEV: //command
26309 FFScript::do_getDMapData_dmapname(true); break;
26310
26311 case DMAPDATASETNAMER: //command
26312 FFScript::do_setDMapData_dmapname(false); break;
26313 case DMAPDATASETNAMEV: //command
26314 FFScript::do_setDMapData_dmapname(true); break;
26315
26316
26317
26318 case DMAPDATAGETTITLER: //command
26319 FFScript::do_getDMapData_dmaptitle(false); break;
26320 case DMAPDATAGETTITLEV: //command
26321 FFScript::do_getDMapData_dmaptitle(true); break;
26322 case DMAPDATASETTITLER: //command
26323 FFScript::do_setDMapData_dmaptitle(false); break;
26324 case DMAPDATASETTITLEV: //command
26325 FFScript::do_setDMapData_dmaptitle(true); break;
26326
26327
26328 case DMAPDATAGETINTROR: //command
26329 FFScript::do_getDMapData_dmapintro(false); break;
26330 case DMAPDATAGETINTROV: //command
26331 FFScript::do_getDMapData_dmapintro(true); break;
26332 case DMAPDATANSETITROR: //command
26333 FFScript::do_setDMapData_dmapintro(false); break;
26334 case DMAPDATASETINTROV: //command
26335 FFScript::do_setDMapData_dmapintro(true); break;
26336
26337
26338 case DMAPDATAGETMUSICR: //command, string to load a music file
26339 FFScript::do_getDMapData_music(false); break;
26340 case DMAPDATAGETMUSICV: //command, string to load a music file
26341 FFScript::do_getDMapData_music(true); break;
26342 case DMAPDATASETMUSICR: //command, string to load a music file
26343 FFScript::do_setDMapData_music(false); break;
26344 case DMAPDATASETMUSICV: //command, string to load a music file
26345 FFScript::do_setDMapData_music(true); break;
26346
26347 case LOADMESSAGEDATAR: //COMMAND
26348 24 FFScript::do_loadmessagedata(false);
26349 24 break;
26350 case LOADMESSAGEDATAV: //COMMAND
26351 FFScript::do_loadmessagedata(false);
26352 break;
26353
26354
26355 case MESSAGEDATASETSTRINGR: //command
26356 24 FFScript::do_messagedata_setstring(false);
26357 24 break;
26358 case MESSAGEDATASETSTRINGV: //command
26359 FFScript::do_messagedata_setstring(false);
26360 break;
26361
26362 case MESSAGEDATAGETSTRINGR: //command
26363 FFScript::do_messagedata_getstring(false);
26364 break;
26365 case MESSAGEDATAGETSTRINGV: //command
26366 FFScript::do_messagedata_getstring(false);
26367 break;
26368 case LOADITEMDATAV:
26369 do_loaditemdata(true);
26370 break;
26371
26372 case LOADNPCBYSUID:
26373 12 FFCore.do_loadnpc_by_script_uid(false);
26374 12 break;
26375
26376 case LOADLWEAPONBYSUID:
26377 598 FFCore.do_loadlweapon_by_script_uid(false);
26378 598 break;
26379
26380 case LOADWEAPONCBYSUID:
26381 FFCore.do_loadeweapon_by_script_uid(false);
26382 break;
26383
26384 case LOADNPCR:
26385 27870027 do_loadnpc(false);
26386 27870027 break;
26387
26388 case LOADNPCV:
26389 do_loadnpc(true);
26390 break;
26391
26392 case CREATELWEAPONR:
26393 87669 do_createlweapon(false);
26394 87669 break;
26395
26396 case CREATELWEAPONV:
26397 do_createlweapon(true);
26398 break;
26399
26400 case CREATEEWEAPONR:
26401 209493 do_createeweapon(false);
26402 209493 break;
26403
26404 case CREATEEWEAPONV:
26405 do_createeweapon(true);
26406 break;
26407
26408 case CREATEITEMR:
26409 22444 do_createitem(false);
26410 22444 break;
26411
26412 case CREATEITEMV:
26413 do_createitem(true);
26414 break;
26415
26416 case CREATENPCR:
26417 3530 do_createnpc(false);
26418 3530 break;
26419
26420 case CREATENPCV:
26421 do_createnpc(true);
26422 break;
26423
26424 case ISVALIDARRAY:
26425 587 do_isvalidarray();
26426 587 break;
26427
26428 case ISVALIDITEM:
26429 31487 do_isvaliditem();
26430 31487 break;
26431
26432 case ISVALIDBITMAP:
26433 5 FFCore.do_isvalidbitmap();
26434 5 break;
26435
26436 case ISALLOCATEDBITMAP:
26437 43 FFCore.do_isallocatedbitmap();
26438 43 break;
26439
26440 case ISVALIDNPC:
26441 11754119 do_isvalidnpc();
26442 11754119 break;
26443
26444 case ISVALIDLWPN:
26445 1205956 do_isvalidlwpn();
26446 1205956 break;
26447
26448 case ISVALIDEWPN:
26449 160009 do_isvalidewpn();
26450 160009 break;
26451
26452 case LWPNMAKEANGULAR:
26453 do_lwpnmakeangular();
26454 break;
26455
26456 case EWPNMAKEANGULAR:
26457 do_ewpnmakeangular();
26458 break;
26459
26460 case LWPNMAKEDIRECTIONAL:
26461 do_lwpnmakedirectional();
26462 break;
26463
26464 case EWPNMAKEDIRECTIONAL:
26465 do_ewpnmakedirectional();
26466 break;
26467
26468 case LWPNUSESPRITER:
26469 19653 do_lwpnusesprite(false);
26470 19653 break;
26471
26472 case LWPNUSESPRITEV:
26473 do_lwpnusesprite(true);
26474 break;
26475
26476 case EWPNUSESPRITER:
26477 208946 do_ewpnusesprite(false);
26478 208946 break;
26479
26480 case EWPNUSESPRITEV:
26481 do_ewpnusesprite(true);
26482 break;
26483
26484 case CLEARSPRITESR:
26485 do_clearsprites(false);
26486 break;
26487
26488 case CLEARSPRITESV:
26489 do_clearsprites(true);
26490 break;
26491
26492 case ISSOLID:
26493 21032557 do_issolid();
26494 21032557 break;
26495
26496 case MAPDATAISSOLID:
26497 do_mapdataissolid();
26498 break;
26499
26500 case MAPDATAISSOLIDLYR:
26501 do_mapdataissolid_layer();
26502 break;
26503
26504 case ISSOLIDLAYER:
26505 do_issolid_layer();
26506 break;
26507
26508 case SETSIDEWARP:
26509 257 do_setsidewarp();
26510 257 break;
26511
26512 case SETTILEWARP:
26513 5 do_settilewarp();
26514 5 break;
26515
26516 case GETSIDEWARPDMAP:
26517 354943 do_getsidewarpdmap(false);
26518 354943 break;
26519
26520 case GETSIDEWARPSCR:
26521 3 do_getsidewarpscr(false);
26522 3 break;
26523
26524 case GETSIDEWARPTYPE:
26525 do_getsidewarptype(false);
26526 break;
26527
26528 case GETTILEWARPDMAP:
26529 354990 do_gettilewarpdmap(false);
26530 354990 break;
26531
26532 case GETTILEWARPSCR:
26533 50 do_gettilewarpscr(false);
26534 50 break;
26535
26536 case GETTILEWARPTYPE:
26537 3 do_gettilewarptype(false);
26538 3 break;
26539
26540 case LAYERSCREEN:
26541 13670631 do_layerscreen();
26542 13670631 break;
26543
26544 case LAYERMAP:
26545 18282859 do_layermap();
26546 18282859 break;
26547
26548 case SECRETS:
26549 357 do_triggersecrets(ri->screenref);
26550 357 break;
26551
26552 case REGION_TRIGGER_SECRETS:
26553 {
26554 118 int screen = get_register(sarg1) / 10000;
26555
1/2
✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
118 if (!is_in_current_region(screen))
26556 {
26557 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
26558 break;
26559 }
26560
26561 118 do_triggersecrets(screen);
26562 118 break;
26563 }
26564
26565 case GRAPHICSGETPIXEL:
26566 FFCore.do_graphics_getpixel();
26567 break;
26568 case GRAPHICSCOUNTCOLOR:
26569 FFCore.do_bmpcollision();
26570 break;
26571
26572 case COMBOTILE:
26573 3062 do_combotile(false);
26574 3062 break;
26575
26576 case DRAWLIGHT_CIRCLE:
26577 {
26578 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26579 {
26580 static const int ARGS = 7;
26581 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26582 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26583 int radius = SH::read_stack(ri->sp + (ARGS-3));
26584 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
26585 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
26586 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
26587 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
26588 if(radius >= 0) radius /= 10000;
26589 else radius = game->get_light_rad();
26590 if(!radius) break;
26591 if(transp_rad >= 0) transp_rad /= 10000;
26592 if(dith_rad >= 0) dith_rad /= 10000;
26593 if(dith_type >= 0) dith_type /= 10000;
26594 if(dith_arg >= 0) dith_arg /= 10000;
26595
26596 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26597 }
26598 else do_drawing_command(scommand, true);
26599
26600 break;
26601 }
26602 case DRAWLIGHT_SQUARE:
26603 {
26604 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26605 {
26606 static const int ARGS = 7;
26607 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26608 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26609 int radius = SH::read_stack(ri->sp + (ARGS-3));
26610 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
26611 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
26612 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
26613 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
26614 if(radius >= 0) radius /= 10000;
26615 else radius = game->get_light_rad();
26616 if(!radius) break;
26617 if(transp_rad >= 0) transp_rad /= 10000;
26618 if(dith_rad >= 0) dith_rad /= 10000;
26619 if(dith_type >= 0) dith_type /= 10000;
26620 if(dith_arg >= 0) dith_arg /= 10000;
26621
26622 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26623 }
26624 else do_drawing_command(scommand, true);
26625
26626 break;
26627 }
26628 case DRAWLIGHT_CONE:
26629 {
26630 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26631 {
26632 static const int ARGS = 8;
26633 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26634 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26635 int dir = SH::read_stack(ri->sp + (ARGS-3)) / 10000;
26636 int length = SH::read_stack(ri->sp + (ARGS-4));
26637 int transp_rad = SH::read_stack(ri->sp + (ARGS-5));
26638 int dith_rad = SH::read_stack(ri->sp + (ARGS-6));
26639 int dith_type = SH::read_stack(ri->sp + (ARGS-7));
26640 int dith_arg = SH::read_stack(ri->sp + (ARGS-8));
26641 if(length >= 0) length /= 10000;
26642 else length = game->get_light_rad()*2;
26643 if(!length) break;
26644 if(dir < 0) break;
26645 else dir = NORMAL_DIR(dir);
26646 if(transp_rad >= 0) transp_rad /= 10000;
26647 if(dith_rad >= 0) dith_rad /= 10000;
26648 if(dith_type >= 0) dith_type /= 10000;
26649 if(dith_arg >= 0) dith_arg /= 10000;
26650
26651 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26652 }
26653 else do_drawing_command(scommand, true);
26654
26655 break;
26656 }
26657
26658 case RECTR:
26659 case CIRCLER:
26660 case ARCR:
26661 case ELLIPSER:
26662 case LINER:
26663 case PUTPIXELR:
26664 case PIXELARRAYR:
26665 case TILEARRAYR:
26666 case LINESARRAY:
26667 case COMBOARRAYR:
26668 case DRAWTILER:
26669 case DRAWTILECLOAKEDR:
26670 case DRAWCOMBOR:
26671 case DRAWCOMBOCLOAKEDR:
26672 case DRAWCHARR:
26673 case DRAWINTR:
26674 case QUADR:
26675 case TRIANGLER:
26676 case QUAD3DR:
26677 case TRIANGLE3DR:
26678 case FASTTILER:
26679 case FASTCOMBOR:
26680 case DRAWSTRINGR:
26681 case DRAWSTRINGR2:
26682 case BMPDRAWSTRINGR2:
26683 case SPLINER:
26684 case BITMAPR:
26685 case BITMAPEXR:
26686 case DRAWLAYERR:
26687 case DRAWSCREENR:
26688 case POLYGONR:
26689 case FRAMER:
26690 case TILEBLIT:
26691 case COMBOBLIT:
26692 45321201 do_drawing_command(scommand, true);
26693 45321201 break;
26694
26695 case BMPRECTR:
26696 case BMPCIRCLER:
26697 case BMPARCR:
26698 case BMPELLIPSER:
26699 case BMPLINER:
26700 case BMPSPLINER:
26701 case BMPPUTPIXELR:
26702 case BMPDRAWTILER:
26703 case BMPDRAWTILECLOAKEDR:
26704 case BMPDRAWCOMBOR:
26705 case BMPDRAWCOMBOCLOAKEDR:
26706 case BMPFASTTILER:
26707 case BMPFASTCOMBOR:
26708 case BMPDRAWCHARR:
26709 case BMPDRAWINTR:
26710 case BMPDRAWSTRINGR:
26711 case BMPQUADR:
26712 case BMPQUAD3DR:
26713 case BMPTRIANGLER:
26714 case BMPTRIANGLE3DR:
26715 case BMPPOLYGONR:
26716 case BMPDRAWLAYERR:
26717 case BMPDRAWLAYERSOLIDR:
26718 case BMPDRAWLAYERCFLAGR:
26719 case BMPDRAWLAYERCTYPER:
26720 case BMPDRAWLAYERCIFLAGR:
26721 case BMPDRAWLAYERSOLIDITYR:
26722 case BMPDRAWSCREENR:
26723 case BMPDRAWSCREENSOLIDR:
26724 case BMPDRAWSCREENSOLID2R:
26725 case BMPDRAWSCREENCOMBOFR:
26726 case BMPDRAWSCREENCOMBOIR:
26727 case BMPDRAWSCREENCOMBOTR:
26728 case BITMAPGETPIXEL:
26729 case BMPBLIT:
26730 case BMPBLITTO:
26731 case BMPTILEBLIT:
26732 case BMPCOMBOBLIT:
26733 case BMPMODE7:
26734 case WRITEBITMAP:
26735 case CLEARBITMAP:
26736 case BITMAPCLEARTOCOLOR:
26737 case BMPFRAMER:
26738 case BMPWRITETILE:
26739 case BMPDITHER:
26740 case BMPREPLCOLOR:
26741 case BMPSHIFTCOLOR:
26742 case BMPMASKDRAW:
26743 case BMPMASKDRAW2:
26744 case BMPMASKDRAW3:
26745 case BMPMASKBLIT:
26746 case BMPMASKBLIT2:
26747 case BMPMASKBLIT3:
26748 53639074 do_drawing_command(scommand, false);
26749 53639074 break;
26750 case READBITMAP:
26751 {
26752 uint32_t bitref = SH::read_stack(ri->sp+2);
26753 if(user_bitmap* b = checkBitmap(bitref,false,true))
26754 do_drawing_command(scommand, false);
26755 else //If the pointer isn't allocated, attempt to allocate it first
26756 {
26757 bitref = FFCore.get_free_bitmap();
26758 ri->d[rEXP2] = bitref; //Return to ptr
26759 if(bitref) SH::write_stack(ri->sp+2,bitref); //Write the ref, for the drawing command to read
26760 else break; //No ref allocated; don't enqueue the drawing command.
26761 do_drawing_command(scommand, false);
26762 }
26763 break;
26764 }
26765 case REGENERATEBITMAP:
26766 {
26767 26528 ri->d[rEXP2] = SH::read_stack(ri->sp+3);
26768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26528 times.
26528 if(user_bitmap* b = checkBitmap(ri->d[rEXP2],false,true))
26769 26528 do_drawing_command(scommand, false);
26770 else //If the pointer isn't allocated
26771 {
26772 int32_t w = SH::read_stack(ri->sp) / 10000;
26773 int32_t h = SH::read_stack(ri->sp+1) / 10000;
26774 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
26775 {
26776 //flip height and width
26777 h = h ^ w;
26778 w = h ^ w;
26779 h = h ^ w;
26780 }
26781
26782 ri->d[rEXP2] = FFCore.create_user_bitmap_ex(h,w); //Return to ptr
26783 }
26784 26528 break;
26785 }
26786
26787 case BITMAPFREE:
26788 {
26789 3512 FFCore.do_deallocate_bitmap();
26790 3512 break;
26791 }
26792
26793 case BITMAPOWN:
26794 {
26795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if(FFCore.isSystemBitref(ri->bitmapref))
26796 break; //Don't attempt to own system bitmaps!
26797
26798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if (auto bitmap = checkBitmap(ri->bitmapref, false))
26799 146 own_script_object(bitmap, type, i);
26800 146 break;
26801 }
26802
26803 case OBJ_OWN_BITMAP:
26804 {
26805 int bmpid = get_register(sarg1);
26806 if(FFCore.isSystemBitref(bmpid))
26807 break; //Don't attempt to own system bitmaps!
26808 user_bitmap* b = checkBitmap(bmpid, false);
26809 if(!b) break;
26810 ScriptType own_type = (ScriptType)sarg2;
26811 int32_t own_i = get_own_i(own_type);
26812 own_script_object(b, own_type, own_i);
26813 break;
26814 }
26815 case OBJ_OWN_PALDATA:
26816 {
26817 int palid = get_register(sarg1);
26818 user_paldata* pd = checkPalData(palid, false);
26819 if(!pd) break;
26820 ScriptType own_type = (ScriptType)sarg2;
26821 int32_t own_i = get_own_i(own_type);
26822 own_script_object(pd, own_type, own_i);
26823 break;
26824 }
26825 case OBJ_OWN_FILE:
26826 {
26827 int fileid = get_register(sarg1);
26828 user_file* f = checkFile(fileid, false);
26829 if(!f) break;
26830 ScriptType own_type = (ScriptType)sarg2;
26831 int32_t own_i = get_own_i(own_type);
26832 own_script_object(f, own_type, own_i);
26833 break;
26834 }
26835 case OBJ_OWN_DIR:
26836 {
26837 int dirid = get_register(sarg1);
26838 user_dir* dr = checkDir(dirid, false);
26839 if(!dr) break;
26840 ScriptType own_type = (ScriptType)sarg2;
26841 int32_t own_i = get_own_i(own_type);
26842 own_script_object(dr, own_type, own_i);
26843 break;
26844 }
26845 case OBJ_OWN_STACK:
26846 {
26847 int stackid = get_register(sarg1);
26848 user_stack* st = checkStack(stackid, false);
26849 if(!st) break;
26850 ScriptType own_type = (ScriptType)sarg2;
26851 int32_t own_i = get_own_i(own_type);
26852 own_script_object(st, own_type, own_i);
26853 break;
26854 }
26855 case OBJ_OWN_RNG:
26856 {
26857 int rngid = get_register(sarg1);
26858 user_rng* r = checkRNG(rngid, false);
26859 if(!r) break;
26860 ScriptType own_type = (ScriptType)sarg2;
26861 int32_t own_i = get_own_i(own_type);
26862 own_script_object(r, own_type, own_i);
26863 break;
26864 }
26865 case OBJ_OWN_ARRAY:
26866 {
26867 int arrid = get_register(sarg1);
26868 ScriptType own_type = (ScriptType)sarg2;
26869 int32_t own_i = get_own_i(own_type);
26870 do_own_array(arrid, own_type, own_i);
26871 break;
26872 }
26873
26874 case COPYTILEVV:
26875 do_copytile(true, true);
26876 break;
26877
26878 case COPYTILEVR:
26879 do_copytile(true, false);
26880 break;
26881
26882 case COPYTILERV:
26883 do_copytile(false, true);
26884 break;
26885
26886 case COPYTILERR:
26887 49233554 do_copytile(false, false);
26888 49233554 break;
26889
26890 case SWAPTILEVV:
26891 do_swaptile(true, true);
26892 break;
26893
26894 case SWAPTILEVR:
26895 do_swaptile(true, false);
26896 break;
26897
26898 case SWAPTILERV:
26899 do_swaptile(false, true);
26900 break;
26901
26902 case SWAPTILERR:
26903 do_swaptile(false, false);
26904 break;
26905
26906 case CLEARTILEV:
26907 do_cleartile(true);
26908 break;
26909
26910 case CLEARTILER:
26911 10 do_cleartile(false);
26912 10 break;
26913
26914 case OVERLAYTILEVV:
26915 do_overlaytile(true, true);
26916 break;
26917
26918 case OVERLAYTILEVR:
26919 do_overlaytile(true, false);
26920 break;
26921
26922 case OVERLAYTILERV:
26923 do_overlaytile(false, true);
26924 break;
26925
26926 case OVERLAYTILERR:
26927 57032 do_overlaytile(false, false);
26928 57032 break;
26929
26930 case FLIPROTTILEVV:
26931 do_fliprotatetile(true, true);
26932 break;
26933
26934 case FLIPROTTILEVR:
26935 do_fliprotatetile(true, false);
26936 break;
26937
26938 case FLIPROTTILERV:
26939 do_fliprotatetile(false, true);
26940 break;
26941
26942 case FLIPROTTILERR:
26943 do_fliprotatetile(false, false);
26944 break;
26945
26946 case GETTILEPIXEL:
26947 do_gettilepixel();
26948 break;
26949
26950 case SETTILEPIXEL:
26951 do_settilepixel();
26952 break;
26953
26954 case SHIFTTILEVV:
26955 do_shifttile(true, true);
26956 break;
26957
26958 case SHIFTTILEVR:
26959 do_shifttile(true, false);
26960 break;
26961
26962 case SHIFTTILERV:
26963 do_shifttile(false, true);
26964 break;
26965
26966 case SHIFTTILERR:
26967 do_shifttile(false, false);
26968 break;
26969
26970 case SETRENDERTARGET:
26971 7069332 do_set_rendertarget(true);
26972 7069332 break;
26973
26974 case GAMEEND:
26975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ( using_SRAM )
26976 {
26977 Z_scripterrlog("Cannot End Game while reading or writing to SRAM. Aborting End. /n");
26978 break;
26979 }
26980 4 Quit = qQUIT;
26981 4 skipcont = 1;
26982 4 scommand = 0xFFFF;
26983 4 break;
26984 case GAMEEXIT:
26985 38 Quit = qEXIT;
26986 38 skipcont = 1;
26987 38 scommand = 0xFFFF;
26988 38 break;
26989 case GAMERELOAD:
26990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if ( using_SRAM )
26991 {
26992 Z_scripterrlog("Cannot Reload Game while reading or writing to SRAM. Aborting Reload. /n");
26993 break;
26994 }
26995 9 Quit = qRELOAD;
26996 9 skipcont = 1;
26997 9 scommand = 0xFFFF;
26998 9 break;
26999 case GAMESETCUSTOMCURSOR:
27000 {
27001 int32_t bmpptr = SH::read_stack(ri->sp + 4);
27002 int fx = SH::read_stack(ri->sp + 3) / 10000;
27003 int fy = SH::read_stack(ri->sp + 2) / 10000;
27004 bool recolor = SH::read_stack(ri->sp + 1)!=0;
27005 bool scale = SH::read_stack(ri->sp + 0)!=0;
27006 if(user_bitmap* b = checkBitmap(bmpptr,true))
27007 {
27008 custom_mouse(b->u_bmp,fx,fy,recolor,scale);
27009 }
27010 break;
27011 }
27012 case CURRENTITEMID:
27013 {
27014 int ity = SH::read_stack(ri->sp + 1) / 10000;
27015 int flags = SH::read_stack(ri->sp + 0) / 10000;
27016 bool checkcost = flags&0x01;
27017 bool checkjinx = flags&0x02;
27018 bool check_bunny = flags&0x04;
27019 ri->d[rEXP1] = current_item_id(ity,checkcost,checkjinx,check_bunny) * 10000;
27020 break;
27021 }
27022
27023 case GAMECONTINUE:
27024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( using_SRAM )
27025 {
27026 Z_scripterrlog("Cannot Continue Game while reading or writing to SRAM. Aborting Continue. /n");
27027 break;
27028 }
27029 2 reset_all_combo_animations();
27030
27031 2 Quit = qCONT;
27032 2 skipcont = 1;
27033 //cont_game();
27034 2 scommand = 0xFFFF;
27035 2 break;
27036
27037 case GAMESAVEQUIT:
27038 if ( using_SRAM )
27039 {
27040 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
27041 break;
27042 }
27043 Quit = qSAVE;
27044 skipcont = 1;
27045 scommand =0xFFFF;
27046 break;
27047
27048 case GAMESAVECONTINUE:
27049 Quit = qSAVECONT;
27050 skipcont = 1;
27051 scommand =0xFFFF;
27052 break;
27053
27054 case SAVE:
27055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if ( using_SRAM )
27056 {
27057 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
27058 break;
27059 }
27060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if(scriptCanSave)
27061 {
27062 30 save_game(false);
27063 30 scriptCanSave=false;
27064 30 }
27065 30 break;
27066
27067 case SAVESCREEN:
27068 do_showsavescreen();
27069 break;
27070
27071 case SHOWF6SCREEN:
27072 onTryQuit();
27073 break;
27074
27075 case SAVEQUITSCREEN:
27076 save_game(false, 1);
27077 break;
27078
27079 //Not Implemented
27080 case ELLIPSE2:
27081 case FLOODFILL:
27082 break;
27083
27084 case ENQUEUER:
27085 do_enqueue(false);
27086 break;
27087
27088 case ENQUEUEV:
27089 do_enqueue(true);
27090 break;
27091
27092 case DEQUEUE:
27093 do_dequeue(false);
27094 break;
27095
27096 //Visual Effects
27097 case WAVYIN:
27098 FFScript::do_wavyin();
27099 break;
27100 case WAVYOUT:
27101 FFScript::do_wavyout();
27102 break;
27103 case ZAPIN:
27104 FFScript::do_zapin();
27105 break;
27106 case ZAPOUT:
27107 FFScript::do_zapout();
27108 break;
27109 case OPENWIPE:
27110 {
27111 FFScript::do_openscreen();
27112 break;
27113 }
27114 case CLOSEWIPE:
27115 {
27116 FFScript::do_closescreen();
27117 break;
27118 }
27119 case OPENWIPESHAPE:
27120 {
27121 FFScript::do_openscreenshape();
27122 break;
27123 }
27124 case CLOSEWIPESHAPE:
27125 {
27126 FFScript::do_closescreenshape();
27127 break;
27128 }
27129
27130 case TINT:
27131 {
27132 3560 FFCore.Tint();
27133 3560 break;
27134 }
27135
27136 case CLEARTINT:
27137 {
27138 66 FFCore.clearTint();
27139 66 break;
27140 }
27141
27142 case MONOHUE:
27143 {
27144 FFCore.gfxmonohue();
27145 break;
27146 }
27147
27148 case SCREENDOSPAWN:
27149 {
27150 ri->d[rEXP1] = scriptloadenemies(ri->screenref) ? 10000 : 0;
27151 break;
27152 }
27153
27154 case SCRTRIGGERCOMBO:
27155 {
27156 int32_t lyr = get_register(sarg1) / 10000;
27157 int32_t pos = get_register(sarg2) / 10000;
27158 rpos_t rpos = (rpos_t)pos;
27159 if (BC::checkComboRpos(rpos) != SH::_NoError)
27160 {
27161 break;
27162 }
27163
27164 set_register(sarg1, do_trigger_combo(get_rpos_handle(rpos, lyr), 0) ? 10000 : 0);
27165 break;
27166 }
27167 case SCRTRIGGERCOMBO2:
27168 {
27169 int32_t lyr = get_register(sarg1) / 10000;
27170 int32_t pos = get_register(sarg2) / 10000;
27171 int32_t idx = get_register(sarg3) / 10000;
27172 rpos_t rpos = (rpos_t)pos;
27173 if (BC::checkComboRpos(rpos) != SH::_NoError)
27174 break;
27175
27176 set_register(sarg1, do_trigger_combo(get_rpos_handle(rpos, lyr), idx) ? 10000 : 0);
27177 break;
27178 }
27179
27180 case SWITCHNPC:
27181 {
27182 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27183 set_register(sarg1,0);
27184 if(Hero.switchhookclk) break; //Already switching!
27185 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
27186 {
27187 switching_object = guys.getByUID(ri->guyref);
27188 hooked_comborpos = rpos_t::None;
27189 hooked_layerbits = 0;
27190 switching_object->switch_hooked = true;
27191 Hero.doSwitchHook(effect);
27192 set_register(sarg1,10000);
27193 }
27194 break;
27195 }
27196
27197 case SWITCHITM:
27198 {
27199 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27200 set_register(sarg1,0);
27201 if(Hero.switchhookclk) break; //Already switching!
27202 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
27203 {
27204 switching_object = ItemH::getItem();
27205 hooked_comborpos = rpos_t::None;
27206 hooked_layerbits = 0;
27207 switching_object->switch_hooked = true;
27208 Hero.doSwitchHook(effect);
27209 set_register(sarg1,10000);
27210 }
27211 break;
27212 }
27213
27214 case SWITCHLW:
27215 {
27216 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27217 set_register(sarg1,0);
27218 if(Hero.switchhookclk) break; //Already switching!
27219 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
27220 {
27221 switching_object = LwpnH::getWeapon();
27222 hooked_comborpos = rpos_t::None;
27223 hooked_layerbits = 0;
27224 switching_object->switch_hooked = true;
27225 Hero.doSwitchHook(effect);
27226 set_register(sarg1,10000);
27227 }
27228 break;
27229 }
27230
27231 case SWITCHEW:
27232 {
27233 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27234 set_register(sarg1,0);
27235 if(Hero.switchhookclk) break; //Already switching!
27236 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
27237 {
27238 switching_object = EwpnH::getWeapon();
27239 hooked_comborpos = rpos_t::None;
27240 hooked_layerbits = 0;
27241 switching_object->switch_hooked = true;
27242 Hero.doSwitchHook(effect);
27243 set_register(sarg1,10000);
27244 }
27245 break;
27246 }
27247
27248 case SWITCHCMB:
27249 {
27250 rpos_t rpos = (rpos_t)(get_register(sarg1)/10000);
27251 set_register(sarg1,0);
27252 if(Hero.switchhookclk) break; //Already switching!
27253 if (!is_valid_rpos(rpos))
27254 break;
27255 switching_object = NULL;
27256 hooked_comborpos = rpos;
27257 hooked_layerbits = 0;
27258 Hero.doSwitchHook(get_register(sarg2)/10000);
27259 if(!hooked_layerbits) //failed
27260 Hero.reset_hookshot();
27261 else set_register(sarg1,10000); //success return
27262 break;
27263 }
27264
27265 case LINKWARPEXR:
27266 {
27267 92 FFCore.do_warp_ex(false);
27268 92 break;
27269 }
27270
27271 case KILLPLAYER:
27272 {
27273 Hero.kill(get_register(sarg1));
27274 break;
27275 }
27276
27277 case HEROMOVEXY:
27278 {
27279 1798 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
27280 1798 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
27281 1798 bool kb = SH::read_stack(ri->sp + 2)!=0;
27282 1798 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27283 1798 bool shove = SH::read_stack(ri->sp + 0)!=0;
27284 1798 ri->d[rEXP1] = Hero.movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
27285 1798 break;
27286 }
27287 case HEROCANMOVEXY:
27288 {
27289 3596 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
27290 3596 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
27291 3596 bool kb = SH::read_stack(ri->sp + 2)!=0;
27292 3596 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27293 3596 bool shove = SH::read_stack(ri->sp + 0)!=0;
27294 3596 ri->d[rEXP1] = Hero.can_movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
27295 3596 break;
27296 }
27297 case HEROMOVEATANGLE:
27298 {
27299 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
27300 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27301 bool kb = SH::read_stack(ri->sp + 2)!=0;
27302 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27303 bool shove = SH::read_stack(ri->sp + 0)!=0;
27304 ri->d[rEXP1] = Hero.moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27305 break;
27306 }
27307 case HEROCANMOVEATANGLE:
27308 {
27309 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
27310 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27311 bool kb = SH::read_stack(ri->sp + 2)!=0;
27312 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27313 bool shove = SH::read_stack(ri->sp + 0)!=0;
27314 ri->d[rEXP1] = Hero.can_moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27315 break;
27316 }
27317 case HEROMOVE:
27318 {
27319 int dir = SH::read_stack(ri->sp + 4)/10000;
27320 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27321 bool kb = SH::read_stack(ri->sp + 2)!=0;
27322 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27323 bool shove = SH::read_stack(ri->sp + 0)!=0;
27324 ri->d[rEXP1] = Hero.moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27325 break;
27326 }
27327 case HEROCANMOVE:
27328 {
27329 440764 int dir = SH::read_stack(ri->sp + 4)/10000;
27330 440764 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27331 440764 bool kb = SH::read_stack(ri->sp + 2)!=0;
27332 440764 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27333 440764 bool shove = SH::read_stack(ri->sp + 0)!=0;
27334 440764 ri->d[rEXP1] = Hero.can_moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27335 440764 break;
27336 }
27337 case HEROLIFTRELEASE:
27338 {
27339 if(Hero.lift_wpn)
27340 {
27341 ri->d[rEXP1] = Hero.lift_wpn->getUID();
27342 Lwpns.add(Hero.lift_wpn);
27343 Hero.lift_wpn = nullptr;
27344 }
27345 else ri->d[rEXP1] = 0;
27346 break;
27347 }
27348 case HEROLIFTGRAB:
27349 {
27350 auto lwuid = SH::read_stack(ri->sp + 2);
27351 auto lifttime = SH::read_stack(ri->sp + 1)/10000;
27352 auto liftheight = zslongToFix(SH::read_stack(ri->sp + 0));
27353 if(weapon* wpn = checkLWpn(lwuid))
27354 {
27355 Hero.lift(wpn, lifttime, liftheight);
27356 if(Lwpns.find(wpn) > -1)
27357 Lwpns.remove(wpn);
27358 if(type == ScriptType::Lwpn && lwuid == i)
27359 earlyretval = RUNSCRIPT_SELFREMOVE;
27360 }
27361 break;
27362 }
27363 case HEROISFLICKERFRAME:
27364 ri->d[rEXP1] = Hero.is_hitflickerframe() ? 10000 : 0;
27365 break;
27366 case LOADPORTAL:
27367 {
27368 auto val = get_register(sarg1)/10000;
27369 if(val != -1)
27370 {
27371 portal* prt = (portal*)portals.spr(val);
27372 if(prt)
27373 val = prt->getUID();
27374 else
27375 {
27376 Z_scripterrlog("Tried to load invalid portal index '%d'\n", val);
27377 val = 0;
27378 }
27379 }
27380 ri->portalref = ri->d[rEXP1] = val;
27381 break;
27382 }
27383 case CREATEPORTAL:
27384 {
27385 portal* p = new portal();
27386 if(portals.add(p))
27387 ri->portalref = ri->d[rEXP1] = p->getUID();
27388 else
27389 {
27390 ri->portalref = ri->d[rEXP1] = 0;
27391 Z_scripterrlog("Unable to create new portal! Limit reached!\n");
27392 }
27393 break;
27394 }
27395 case LOADSAVPORTAL:
27396 {
27397 auto val = get_register(sarg1)/10000;
27398 savedportal* prt = checkSavedPortal(val);
27399 ri->saveportalref = ri->d[rEXP1] = prt ? val : 0;
27400 break;
27401 }
27402 case CREATESAVPORTAL:
27403 {
27404 if(game->user_portals.size() >= MAX_SAVED_PORTALS)
27405 {
27406 ri->saveportalref = ri->d[rEXP1] = 0;
27407 Z_scripterrlog("Cannot create any more Saved Portals! Remove some first!\n");
27408 break;
27409 }
27410 savedportal& ref = game->user_portals.emplace_back();
27411 ri->saveportalref = ri->d[rEXP1] = ref.getUID();
27412 break;
27413 }
27414 case PORTALREMOVE:
27415 {
27416 if(portal* p = checkPortal(ri->portalref, true))
27417 {
27418 if(p == &mirror_portal)
27419 p->clear();
27420 else
27421 {
27422 auto id = portals.find(p);
27423 if(id > -1)
27424 portals.del(id,true);
27425 }
27426 }
27427 break;
27428 }
27429 case PORTALUSESPRITE:
27430 do_portalusesprite();
27431 break;
27432 case SAVEDPORTALREMOVE:
27433 {
27434 if(savedportal* sp = checkSavedPortal(ri->saveportalref, true))
27435 {
27436 if(sp == &(game->saved_mirror_portal))
27437 sp->clear();
27438 else
27439 {
27440 //ensure all pointers to the object are cleared before deleting
27441 portals.forEach([&](sprite& spr)
27442 {
27443 portal* tmp = (portal*)&spr;
27444 if(sp->getUID() == tmp->saved_data)
27445 {
27446 tmp->saved_data = 0;
27447 }
27448 return false;
27449 });
27450 //delete the savedportal object from the vector
27451 for(auto it = game->user_portals.begin();
27452 it != game->user_portals.end();)
27453 {
27454 savedportal& tmp = *it;
27455 if(sp == &tmp)
27456 {
27457 game->user_portals.erase(it);
27458 break;
27459 }
27460 else ++it;
27461 }
27462 }
27463 }
27464 break;
27465 }
27466 case SAVEDPORTALGENERATE:
27467 {
27468 auto retval = 0;
27469 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
27470 {
27471 retval = getPortalFromSaved(sp);
27472 if(!retval)
27473 {
27474 if(portal* p = loadportal(*sp))
27475 if(portals.add(p))
27476 retval = p->getUID();
27477 }
27478 }
27479 ri->d[rEXP1] = retval;
27480 break;
27481 }
27482
27483 case LINKEXPLODER:
27484 {
27485 int32_t mode = get_register(sarg1) / 10000;
27486 if ( (unsigned) mode > 2 )
27487 {
27488 Z_scripterrlog("Invalid mode (%d) passed to Hero->Explode(int32_t mode)\n",mode);
27489 }
27490 else Hero.explode(mode);
27491 break;
27492 }
27493 case NPCEXPLODER:
27494 {
27495 int32_t mode = get_register(sarg1) / 10000;
27496 if ( (unsigned) mode > 2 )
27497 {
27498 Z_scripterrlog("Invalid mode (%d) passed to npc->Explode(int32_t mode)\n",mode);
27499 }
27500 else
27501 {
27502 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
27503 {
27504 GuyH::getNPC()->explode(mode);
27505 }
27506 }
27507 break;
27508 }
27509
27510 case ITEMEXPLODER:
27511 {
27512
27513 int32_t mode = get_register(sarg1) / 10000;
27514 if ( (unsigned) mode > 2 )
27515 {
27516 Z_scripterrlog("Invalid mode (%d) passed to item->Explode(int32_t mode)\n",mode);
27517 }
27518 else
27519 {
27520 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
27521 {
27522 ItemH::getItem()->explode(mode);
27523 }
27524 }
27525 break;
27526 }
27527 case LWEAPONEXPLODER:
27528 {
27529 int32_t mode = get_register(sarg1) / 10000;
27530 if ( (unsigned) mode > 2 )
27531 {
27532 Z_scripterrlog("Invalid mode (%d) passed to lweapon->Explode(int32_t mode)\n",mode);
27533 }
27534 else
27535 {
27536 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
27537 {
27538 LwpnH::getWeapon()->explode(mode);
27539 }
27540 }
27541 break;
27542 }
27543 case EWEAPONEXPLODER:
27544 {
27545 int32_t mode = get_register(sarg1) / 10000;
27546 if ( (unsigned) mode > 2 )
27547 {
27548 Z_scripterrlog("Invalid mode (%d) passed to eweapon->Explode(int32_t mode)\n",mode);
27549 }
27550 else
27551 {
27552 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
27553 {
27554 EwpnH::getWeapon()->explode(mode);
27555 }
27556 }
27557 break;
27558 }
27559
27560 case BOTTLENAMEGET:
27561 {
27562 int32_t arrayptr = get_register(sarg1);
27563 int32_t id = ri->bottletyperef-1;
27564 if(unsigned(id) > 63)
27565 {
27566 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->GetName().\n", id);
27567 break;
27568 }
27569
27570 if(ArrayH::setArray(arrayptr, QMisc.bottle_types[id].name) == SH::_Overflow)
27571 Z_scripterrlog("Array supplied to 'bottledata->GetName()' not large enough\n");
27572 break;
27573 }
27574 case BOTTLENAMESET:
27575 {
27576 int32_t arrayptr = get_register(sarg1);
27577 int32_t id = ri->bottletyperef-1;
27578 if(unsigned(id) > 63)
27579 {
27580 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->SetName().\n", id+1);
27581 break;
27582 }
27583 string name;
27584 ArrayH::getString(arrayptr, name, 31);
27585 strcpy(QMisc.bottle_types[id].name, name.c_str());
27586 break;
27587 }
27588 case BSHOPNAMEGET:
27589 {
27590 int32_t arrayptr = get_register(sarg1);
27591 int32_t id = ri->bottleshopref-1;
27592 if(unsigned(id) > 255)
27593 {
27594 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->GetName().\n", id+1);
27595 break;
27596 }
27597
27598 if(ArrayH::setArray(arrayptr, QMisc.bottle_shop_types[id].name) == SH::_Overflow)
27599 Z_scripterrlog("Array supplied to 'bottleshopdata->GetName()' not large enough\n");
27600 break;
27601 }
27602 case BSHOPNAMESET:
27603 {
27604 int32_t arrayptr = get_register(sarg1);
27605 int32_t id = ri->bottleshopref;
27606 if(unsigned(id) > 255)
27607 {
27608 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->SetName().\n", id);
27609 break;
27610 }
27611 string name;
27612 ArrayH::getString(arrayptr, name, 31);
27613 strcpy(QMisc.bottle_shop_types[id].name, name.c_str());
27614 break;
27615 }
27616
27617 case RUNITEMSCRIPT:
27618 {
27619 15 int32_t itemid = ri->idata;
27620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(unsigned(itemid) > MAXITEMS) break;
27621 15 int32_t mode = get_register(sarg1) / 10000;
27622 15 auto& data = get_script_engine_data(ScriptType::Item, itemid);
27623
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
15 switch(mode)
27624 {
27625 case 0:
27626 {
27627 data.doscript = 4;
27628 break;
27629 }
27630 case 1:
27631 {
27632 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27633 {
27634 if ( !data.doscript )
27635 {
27636 data.clear_ref();
27637 data.doscript = 1;
27638 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid);
27639 }
27640 else
27641 {
27642 //Emily, clear the stack here, clear refinfo, and set up to run again on the next frame from the beginning.
27643 }
27644 }
27645 break;
27646 }
27647 15 case 2:
27648 default:
27649 {
27650
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27651 {
27652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (data.doscript != 2 )data.doscript = 2;
27653 15 }
27654 15 break;
27655 }
27656 /*
27657 case 0:
27658 {
27659 data.doscript = 0;
27660 break;
27661 }
27662 default:
27663 {
27664
27665 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27666 {
27667 //itemScriptData[itemid].Clear();
27668 //for ( int32_t q = 0; q < 1024; q++ ) item_stack[itemid][q] = 0;
27669 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid & 0xFFF);
27670 data.doscript = 2;
27671 }
27672 break;
27673 }
27674 */
27675 }
27676 15 break;
27677 }
27678
27679 //case NPCData
27680
27681 case GETNPCDATATILE: FFScript::getNPCData_tile(); break;
27682 case GETNPCDATAEHEIGHT: FFScript::getNPCData_e_height(); break;
27683 case GETNPCDATAFLAGS: FFScript::getNPCData_flags(); break;
27684 case GETNPCDATAFLAGS2: FFScript::getNPCData_flags2(); break;
27685 case GETNPCDATAWIDTH: FFScript::getNPCData_width(); break;
27686 case GETNPCDATAHEIGHT: FFScript::getNPCData_height(); break;
27687 case GETNPCDATASTILE: FFScript::getNPCData_s_tile(); break;
27688 case GETNPCDATASWIDTH: FFScript::getNPCData_s_width(); break;
27689 case GETNPCDATASHEIGHT: FFScript::getNPCData_s_height(); break;
27690 case GETNPCDATAETILE: FFScript::getNPCData_e_tile(); break;
27691 case GETNPCDATAEWIDTH: FFScript::getNPCData_e_width(); break;
27692 case GETNPCDATAHP: FFScript::getNPCData_hp(); break;
27693 case GETNPCDATAFAMILY: FFScript::getNPCData_family(); break;
27694 case GETNPCDATACSET: FFScript::getNPCData_cset(); break;
27695 case GETNPCDATAANIM: FFScript::getNPCData_anim(); break;
27696 case GETNPCDATAEANIM: FFScript::getNPCData_e_anim(); break;
27697 case GETNPCDATAFRAMERATE: FFScript::getNPCData_frate(); break;
27698 case GETNPCDATAEFRAMERATE: FFScript::getNPCData_e_frate(); break;
27699 case GETNPCDATATOUCHDMG: FFScript::getNPCData_dp(); break;
27700 case GETNPCDATAWPNDAMAGE: FFScript::getNPCData_wdp(); break;
27701 case GETNPCDATAWEAPON: FFScript::getNPCData_wdp(); break;
27702 case GETNPCDATARANDOM: FFScript::getNPCData_rate(); break;
27703 case GETNPCDATAHALT: FFScript::getNPCData_hrate(); break;
27704 case GETNPCDATASTEP: FFScript::getNPCData_step(); break;
27705 case GETNPCDATAHOMING: FFScript::getNPCData_homing(); break;
27706 case GETNPCDATAHUNGER: FFScript::getNPCData_grumble(); break;
27707 case GETNPCDATADROPSET: FFScript::getNPCData_item_set(); break;
27708 case GETNPCDATABGSFX: FFScript::getNPCData_bgsfx(); break;
27709 case GETNPCDATADEATHSFX: FFScript::getNPCData_deadsfx(); break;
27710 case GETNPCDATAXOFS: FFScript::getNPCData_xofs(); break;
27711 case GETNPCDATAYOFS: FFScript::getNPCData_yofs(); break;
27712 case GETNPCDATAZOFS: FFScript::getNPCData_zofs(); break;
27713 case GETNPCDATAHXOFS: FFScript::getNPCData_hxofs(); break;
27714 case GETNPCDATAHYOFS: FFScript::getNPCData_hyofs(); break;
27715 case GETNPCDATAHITWIDTH: FFScript::getNPCData_hxsz(); break;
27716 case GETNPCDATAHITHEIGHT: FFScript::getNPCData_hysz(); break;
27717 case GETNPCDATAHITZ: FFScript::getNPCData_hzsz(); break;
27718 case GETNPCDATATILEWIDTH: FFScript::getNPCData_txsz(); break;
27719 case GETNPCDATATILEHEIGHT: FFScript::getNPCData_tysz(); break;
27720 case GETNPCDATAWPNSPRITE: FFScript::getNPCData_wpnsprite(); break;
27721 //case GETNPCDATASCRIPTDEF: FFScript::getNPCData_scriptdefence(); break; //2.future cross-compat.
27722 case GETNPCDATADEFENSE: FFScript::getNPCData_defense(); break;
27723 case GETNPCDATASIZEFLAG: FFScript::getNPCData_SIZEflags(); break;
27724 case GETNPCDATAATTRIBUTE: FFScript::getNPCData_misc(); break;
27725 case GETNPCDATAHITSFX: FFScript::getNPCData_hitsfx(); break;
27726
27727 case SETNPCDATAFLAGS: FFScript::setNPCData_flags(); break;
27728 case SETNPCDATAFLAGS2: FFScript::setNPCData_flags2(); break;
27729 case SETNPCDATAWIDTH: FFScript::setNPCData_width(); break;
27730 case SETNPCDATAHEIGHT: FFScript::setNPCData_height(); break;
27731 case SETNPCDATASTILE: FFScript::setNPCData_s_tile(); break;
27732 case SETNPCDATASWIDTH: FFScript::setNPCData_s_width(); break;
27733 case SETNPCDATASHEIGHT: FFScript::setNPCData_s_height(); break;
27734 case SETNPCDATAETILE: FFScript::setNPCData_e_tile(); break;
27735 case SETNPCDATAEWIDTH: FFScript::setNPCData_e_width(); break;
27736 case SETNPCDATAHP: FFScript::setNPCData_hp(); break;
27737 case SETNPCDATAFAMILY: FFScript::setNPCData_family(); break;
27738 case SETNPCDATACSET: FFScript::setNPCData_cset(); break;
27739 case SETNPCDATAANIM: FFScript::setNPCData_anim(); break;
27740 case SETNPCDATAEANIM: FFScript::setNPCData_e_anim(); break;
27741 case SETNPCDATAFRAMERATE: FFScript::setNPCData_frate(); break;
27742 case SETNPCDATAEFRAMERATE: FFScript::setNPCData_e_frate(); break;
27743 case SETNPCDATATOUCHDMG: FFScript::setNPCData_dp(); break;
27744 case SETNPCDATAWPNDAMAGE: FFScript::setNPCData_wdp(); break;
27745 case SETNPCDATAWEAPON: FFScript::setNPCData_weapon(); break;
27746 case SETNPCDATARANDOM: FFScript::setNPCData_rate(); break;
27747 case SETNPCDATAHALT: FFScript::setNPCData_hrate(); break;
27748 case SETNPCDATASTEP: FFScript::setNPCData_step(); break;
27749 case SETNPCDATAHOMING: FFScript::setNPCData_homing(); break;
27750 case SETNPCDATAHUNGER: FFScript::setNPCData_grumble(); break;
27751 case SETNPCDATADROPSET: FFScript::setNPCData_item_set(); break;
27752 case SETNPCDATABGSFX: FFScript::setNPCData_bgsfx(); break;
27753 case SETNPCDATADEATHSFX: FFScript::setNPCData_hitsfx(); break;
27754 case SETNPCDATAXOFS: FFScript::setNPCData_xofs(); break;
27755 case SETNPCDATAYOFS: FFScript::setNPCData_yofs(); break;
27756 case SETNPCDATAZOFS: FFScript::setNPCData_zofs(); break;
27757 case SETNPCDATAHXOFS: FFScript::setNPCData_hxofs(); break;
27758 case SETNPCDATAHYOFS: FFScript::setNPCData_hyofs(); break;
27759 case SETNPCDATAHITWIDTH: FFScript::setNPCData_hxsz(); break;
27760 case SETNPCDATAHITHEIGHT: FFScript::setNPCData_hysz(); break;
27761 case SETNPCDATAHITZ: FFScript::setNPCData_hzsz(); break;
27762 case SETNPCDATATILEWIDTH: FFScript::setNPCData_txsz(); break;
27763 case SETNPCDATATILEHEIGHT: FFScript::setNPCData_tysz(); break;
27764 case SETNPCDATAWPNSPRITE: FFScript::setNPCData_wpnsprite(); break;
27765 case SETNPCDATAHITSFX: FFScript::setNPCData_hitsfx(); break;
27766 case SETNPCDATATILE: FFScript::setNPCData_tile(); break;
27767 case SETNPCDATAEHEIGHT: FFScript::setNPCData_e_height(); break;
27768
27769
27770
27771
27772
27773
27774 //case SETNPCDATASCRIPTDEF : FFScript::setNPCData_scriptdefence(); break;
27775 case SETNPCDATADEFENSE : FFScript::setNPCData_defense(ri->d[rEXP1]); break;
27776 case SETNPCDATASIZEFLAG : FFScript::setNPCData_SIZEflags(ri->d[rEXP1]); break;
27777 case SETNPCDATAATTRIBUTE : FFScript::setNPCData_misc(ri->d[rEXP1]); break;
27778
27779
27780 //ComboData
27781
27782 case GCDBLOCKENEM: FFScript::getComboData_block_enemies(); break;
27783 case GCDBLOCKHOLE: FFScript::getComboData_block_hole(); break;
27784 case GCDBLOCKTRIG: FFScript::getComboData_block_trigger(); break;
27785 case GCDCONVEYSPDX: FFScript::getComboData_conveyor_x_speed(); break;
27786 case GCDCONVEYSPDY: FFScript::getComboData_conveyor_y_speed(); break;
27787 case GCDCREATEENEM: FFScript::getComboData_create_enemy(); break;
27788 case GCDCREATEENEMWH: FFScript::getComboData_create_enemy_when(); break;
27789 case GCDCREATEENEMCH: FFScript::getComboData_create_enemy_change(); break;
27790 case GCDDIRCHTYPE: FFScript::getComboData_directional_change_type(); break;
27791 case GCDDISTCHTILES: FFScript::getComboData_distance_change_tiles(); break;
27792 case GCDDIVEITEM: FFScript::getComboData_dive_item(); break;
27793 case GCDDOCK: FFScript::getComboData_dock(); break;
27794 case GCDFAIRY: FFScript::getComboData_fairy(); break;
27795 case GCDFFCOMBOATTRIB: FFScript::getComboData_ff_combo_attr_change(); break;
27796 case GCDFOOTDECOTILE: FFScript::getComboData_foot_decorations_tile(); break;
27797 case GCDFOOTDECOTYPE: FFScript::getComboData_foot_decorations_type(); break;
27798 case GCDHOOKSHOTGRAB: FFScript::getComboData_hookshot_grab_point(); break;
27799 case GCDLADDERPASS: FFScript::getComboData_ladder_pass(); break;
27800 case GCDLOCKBLOCKTYPE: FFScript::getComboData_lock_block_type(); break;
27801 case GCDLOCKBLOCKCHANGE: FFScript::getComboData_lock_block_change(); break;
27802 case GCDMAGICMIRRORTYPE: FFScript::getComboData_magic_mirror_type(); break;
27803 case GCDMODIFYHPAMOUNT: FFScript::getComboData_modify_hp_amount(); break;
27804 case GCDMODIFYHPDELAY: FFScript::getComboData_modify_hp_delay(); break;
27805 case GCDMODIFYHPTYPE: FFScript::getComboData_modify_hp_type(); break;
27806 case GCDMODIFYMPAMOUNT: FFScript::getComboData_modify_mp_amount(); break;
27807 case GCDMODIFYMPDELAY: FFScript::getComboData_modify_mp_delay(); break;
27808 case GCDMODIFYMPTYPE: FFScript::getComboData_modify_mp_type(); break;
27809 case GCDNOPUSHBLOCKS: FFScript::getComboData_no_push_blocks(); break;
27810 case GCDOVERHEAD: FFScript::getComboData_overhead(); break;
27811 case GCDPLACEENEMY: FFScript::getComboData_place_enemy(); break;
27812 case GCDPUSHDIR: FFScript::getComboData_push_direction(); break;
27813 case GCDPUSHWEIGHT: FFScript::getComboData_push_weight(); break;
27814 case GCDPUSHWAIT: FFScript::getComboData_push_wait(); break;
27815 case GCDPUSHED: FFScript::getComboData_pushed(); break;
27816 case GCDRAFT: FFScript::getComboData_raft(); break;
27817 case GCDRESETROOM: FFScript::getComboData_reset_room(); break;
27818 case GCDSAVEPOINT: FFScript::getComboData_save_point_type(); break;
27819 case GCDSCREENFREEZE: FFScript::getComboData_screen_freeze_type(); break;
27820 case GCDSECRETCOMBO: FFScript::getComboData_secret_combo(); break;
27821 case GCDSINGULAR: FFScript::getComboData_singular(); break;
27822 case GCDSLOWMOVE: FFScript::getComboData_slow_movement(); break;
27823 case GCDSTATUE: FFScript::getComboData_statue_type(); break;
27824 case GCDSTEPTYPE: FFScript::getComboData_step_type(); break;
27825 case GCDSTEPCHANGETO: FFScript::getComboData_step_change_to(); break;
27826 case GCDSTRIKEREMNANTS: FFScript::getComboData_strike_remnants(); break;
27827 case GCDSTRIKEREMNANTSTYPE: FFScript::getComboData_strike_remnants_type(); break;
27828 case GCDSTRIKECHANGE: FFScript::getComboData_strike_change(); break;
27829 case GCDSTRIKECHANGEITEM: FFScript::getComboData_strike_item(); break;
27830 case GCDTOUCHITEM: FFScript::getComboData_touch_item(); break;
27831 case GCDTOUCHSTAIRS: FFScript::getComboData_touch_stairs(); break;
27832 case GCDTRIGGERTYPE: FFScript::getComboData_trigger_type(); break;
27833 case GCDTRIGGERSENS: FFScript::getComboData_trigger_sensitive(); break;
27834 case GCDWARPTYPE: FFScript::getComboData_warp_type(); break;
27835 case GCDWARPSENS: FFScript::getComboData_warp_sensitive(); break;
27836 case GCDWARPDIRECT: FFScript::getComboData_warp_direct(); break;
27837 case GCDWARPLOCATION: FFScript::getComboData_warp_location(); break;
27838 case GCDWATER: FFScript::getComboData_water(); break;
27839 case GCDWHISTLE: FFScript::getComboData_whistle(); break;
27840 case GCDWINGAME: FFScript::getComboData_win_game(); break;
27841 case GCDBLOCKWEAPLVL: FFScript::getComboData_block_weapon_lvl(); break;
27842 case GCDTILE: FFScript::getComboData_tile(); break;
27843 case GCDFLIP: FFScript::getComboData_flip(); break;
27844 case GCDWALK: FFScript::getComboData_walk(); break;
27845 case GCDTYPE: FFScript::getComboData_type(); break;
27846 case GCDCSETS: FFScript::getComboData_csets(); break;
27847 case GCDFOO: break;
27848 case GCDFRAMES: FFScript::getComboData_frames(); break;
27849 case GCDSPEED: FFScript::getComboData_speed(); break;
27850 case GCDNEXTCOMBO: FFScript::getComboData_nextcombo(); break;
27851 case GCDNEXTCSET: FFScript::getComboData_nextcset(); break;
27852 case GCDFLAG: FFScript::getComboData_flag(); break;
27853 case GCDSKIPANIM: FFScript::getComboData_skipanim(); break;
27854 case GCDNEXTTIMER: FFScript::getComboData_nexttimer(); break;
27855 case GCDSKIPANIMY: FFScript::getComboData_skipanimy(); break;
27856 case GCDANIMFLAGS: FFScript::getComboData_animflags(); break;
27857 case GCDBLOCKWEAPON: FFScript::getComboData_block_weapon(); break;
27858 case GCDSTRIKEWEAPONS: FFScript::getComboData_strike_weapons(); break;
27859 case SCDBLOCKENEM: FFScript::setComboData_block_enemies(); break;
27860 case SCDBLOCKHOLE: FFScript::setComboData_block_hole(); break;
27861 case SCDBLOCKTRIG: FFScript::setComboData_block_trigger(); break;
27862 case SCDCONVEYSPDX: FFScript::setComboData_conveyor_x_speed(); break;
27863 case SCDCONVEYSPDY: FFScript::setComboData_conveyor_y_speed(); break;
27864 case SCDCREATEENEM: FFScript::setComboData_create_enemy(); break;
27865 case SCDCREATEENEMWH: FFScript::setComboData_create_enemy_when(); break;
27866 case SCDCREATEENEMCH: FFScript::setComboData_create_enemy_change(); break;
27867 case SCDDIRCHTYPE: FFScript::setComboData_directional_change_type(); break;
27868 case SCDDISTCHTILES: FFScript::setComboData_distance_change_tiles(); break;
27869 case SCDDIVEITEM: FFScript::setComboData_dive_item(); break;
27870 case SCDDOCK: FFScript::setComboData_dock(); break;
27871 case SCDFAIRY: FFScript::setComboData_fairy(); break;
27872 case SCDFFCOMBOATTRIB: FFScript::setComboData_ff_combo_attr_change(); break;
27873 case SCDFOOTDECOTILE: FFScript::setComboData_foot_decorations_tile(); break;
27874 case SCDFOOTDECOTYPE: FFScript::setComboData_foot_decorations_type(); break;
27875 case SCDHOOKSHOTGRAB: FFScript::setComboData_hookshot_grab_point(); break;
27876 case SCDLADDERPASS: FFScript::setComboData_ladder_pass(); break;
27877 case SCDLOCKBLOCKTYPE: FFScript::setComboData_lock_block_type(); break;
27878 case SCDLOCKBLOCKCHANGE: FFScript::setComboData_lock_block_change(); break;
27879 case SCDMAGICMIRRORTYPE: FFScript::setComboData_magic_mirror_type(); break;
27880 case SCDMODIFYHPAMOUNT: FFScript::setComboData_modify_hp_amount(); break;
27881 case SCDMODIFYHPDELAY: FFScript::setComboData_modify_hp_delay(); break;
27882 case SCDMODIFYHPTYPE: FFScript::setComboData_modify_hp_type(); break;
27883 case SCDMODIFYMPAMOUNT: FFScript::setComboData_modify_mp_amount(); break;
27884 case SCDMODIFYMPDELAY: FFScript::setComboData_modify_mp_delay(); break;
27885 case SCDMODIFYMPTYPE: FFScript::setComboData_modify_mp_type(); break;
27886 case SCDNOPUSHBLOCKS: FFScript::setComboData_no_push_blocks(); break;
27887 case SCDOVERHEAD: FFScript::setComboData_overhead(); break;
27888 case SCDPLACEENEMY: FFScript::setComboData_place_enemy(); break;
27889 case SCDPUSHDIR: FFScript::setComboData_push_direction(); break;
27890 case SCDPUSHWEIGHT: FFScript::setComboData_push_weight(); break;
27891 case SCDPUSHWAIT: FFScript::setComboData_push_wait(); break;
27892 case SCDPUSHED: FFScript::setComboData_pushed(); break;
27893 case SCDRAFT: FFScript::setComboData_raft(); break;
27894 case SCDRESETROOM: FFScript::setComboData_reset_room(); break;
27895 case SCDSAVEPOINT: FFScript::setComboData_save_point_type(); break;
27896 case SCDSCREENFREEZE: FFScript::setComboData_screen_freeze_type(); break;
27897 case SCDSECRETCOMBO: FFScript::setComboData_secret_combo(); break;
27898 case SCDSINGULAR: FFScript::setComboData_singular(); break;
27899 case SCDSLOWMOVE: FFScript::setComboData_slow_movement(); break;
27900 case SCDSTATUE: FFScript::setComboData_statue_type(); break;
27901 case SCDSTEPTYPE: FFScript::setComboData_step_type(); break;
27902 case SCDSTEPCHANGETO: FFScript::setComboData_step_change_to(); break;
27903 case SCDSTRIKEREMNANTS: FFScript::setComboData_strike_remnants(); break;
27904 case SCDSTRIKEREMNANTSTYPE: FFScript::setComboData_strike_remnants_type(); break;
27905 case SCDSTRIKECHANGE: FFScript::setComboData_strike_change(); break;
27906 case SCDSTRIKECHANGEITEM: FFScript::setComboData_strike_item(); break;
27907 case SCDTOUCHITEM: FFScript::setComboData_touch_item(); break;
27908 case SCDTOUCHSTAIRS: FFScript::setComboData_touch_stairs(); break;
27909 case SCDTRIGGERTYPE: FFScript::setComboData_trigger_type(); break;
27910 case SCDTRIGGERSENS: FFScript::setComboData_trigger_sensitive(); break;
27911 case SCDWARPTYPE: FFScript::setComboData_warp_type(); break;
27912 case SCDWARPSENS: FFScript::setComboData_warp_sensitive(); break;
27913 case SCDWARPDIRECT: FFScript::setComboData_warp_direct(); break;
27914 case SCDWARPLOCATION: FFScript::setComboData_warp_location(); break;
27915 case SCDWATER: FFScript::setComboData_water(); break;
27916 case SCDWHISTLE: FFScript::setComboData_whistle(); break;
27917 case SCDWINGAME: FFScript::setComboData_win_game(); break;
27918 case SCDBLOCKWEAPLVL: FFScript::setComboData_block_weapon_lvl(); break;
27919 case SCDTILE: FFScript::setComboData_tile(); break;
27920 case SCDFLIP: FFScript::setComboData_flip(); break;
27921 case SCDWALK: FFScript::setComboData_walk(); break;
27922 case SCDTYPE: FFScript::setComboData_type(); break;
27923 case SCDCSETS: FFScript::setComboData_csets(); break;
27924 case SCDFOO: break;
27925 case SCDFRAMES: FFScript::setComboData_frames(); break;
27926 case SCDSPEED: FFScript::setComboData_speed(); break;
27927 case SCDNEXTCOMBO: FFScript::setComboData_nextcombo(); break;
27928 case SCDNEXTCSET: FFScript::setComboData_nextcset(); break;
27929 case SCDFLAG: FFScript::setComboData_flag(); break;
27930 case SCDSKIPANIM: FFScript::setComboData_skipanim(); break;
27931 case SCDNEXTTIMER: FFScript::setComboData_nexttimer(); break;
27932 case SCDSKIPANIMY: FFScript::setComboData_skipanimy(); break;
27933 case SCDANIMFLAGS: FFScript::setComboData_animflags(); break;
27934 case SCDBLOCKWEAPON: FFScript::setComboData_block_weapon(ri->d[rEXP1]); break;
27935 case SCDSTRIKEWEAPONS: FFScript::setComboData_strike_weapons(ri->d[rEXP1]); break;
27936
27937 //SpriteData
27938
27939 //case GETSPRITEDATASTRING:
27940 case GETSPRITEDATATILE: FFScript::getSpriteDataTile(); break;
27941 case GETSPRITEDATAMISC: FFScript::getSpriteDataCSets(); break;
27942 case GETSPRITEDATACGETS: FFScript::getSpriteDataCSets(); break;
27943 case GETSPRITEDATAFRAMES: FFScript::getSpriteDataFrames(); break;
27944 case GETSPRITEDATASPEED: FFScript::getSpriteDataSpeed(); break;
27945 case GETSPRITEDATATYPE: FFScript::getSpriteDataType(); break;
27946
27947 //case SETSPRITEDATASTRING:
27948 case SETSPRITEDATATILE: FFScript::setSpriteDataTile(); break;
27949 case SETSPRITEDATAMISC: FFScript::setSpriteDataMisc(); break;
27950 case SETSPRITEDATACSETS: FFScript::setSpriteDataCSets(); break;
27951 case SETSPRITEDATAFRAMES: FFScript::setSpriteDataFrames(); break;
27952 case SETSPRITEDATASPEED: FFScript::setSpriteDataSpeed(); break;
27953 case SETSPRITEDATATYPE: FFScript::setSpriteDataType(); break;
27954
27955 //Game over Screen
27956 case SETCONTINUESCREEN: FFScript::FFChangeSubscreenText(); break;
27957 case SETCONTINUESTRING: FFScript::FFSetSaveScreenSetting(); break;
27958
27959 case LWPNDEL:
27960 {
27961
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
10 if(type == ScriptType::Lwpn && ri->lwpn == i)
27962 {
27963 8 FFCore.do_lweapon_delete();
27964 8 return RUNSCRIPT_SELFDELETE;
27965 }
27966
27967 2 FFCore.do_lweapon_delete();
27968 2 break;
27969 }
27970 case EWPNDEL:
27971 {
27972
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
46 if(type == ScriptType::Ewpn && ri->ewpn == i)
27973 {
27974 10 FFCore.do_eweapon_delete();
27975 10 return RUNSCRIPT_SELFDELETE;
27976 }
27977
27978 36 FFCore.do_eweapon_delete();
27979 36 break;
27980 }
27981
27982 case PLAYENHMUSICEX:
27983 // DEPRECATED
27984 do_enh_music(false);
27985 break;
27986
27987 case GETENHMUSICPOS:
27988 FFCore.do_get_music_position();
27989 break;
27990
27991 case SETENHMUSICPOS:
27992 FFCore.do_set_music_position(false);
27993 break;
27994
27995 case SETENHMUSICSPEED:
27996 FFCore.do_set_music_speed(false);
27997 break;
27998
27999 case GETENHMUSICLEN:
28000 FFCore.do_get_music_length();
28001 break;
28002
28003 case SETENHMUSICLOOP:
28004 3 FFCore.do_set_music_loop();
28005 3 break;
28006
28007 case ENHCROSSFADE:
28008 5 do_enh_music_crossfade();
28009 5 break;
28010
28011 case DIREXISTS:
28012 FFCore.do_checkdir(true);
28013 break;
28014
28015 case FILEEXISTS:
28016 FFCore.do_checkdir(false);
28017 break;
28018
28019 case FILESYSREMOVE:
28020 FFCore.do_fs_remove();
28021 break;
28022
28023 case TOBYTE:
28024 do_tobyte();
28025 break;
28026 case TOWORD:
28027 do_toword();
28028 break;
28029 case TOSHORT: do_toshort(); break;
28030 case TOSIGNEDBYTE: do_tosignedbyte(); break;
28031 case TOINTEGER: do_tointeger(); break;
28032 6877 case CEILING: do_ceiling(); break;
28033 291091 case FLOOR: do_floor(); break;
28034 case TRUNCATE: do_trunc(); break;
28035 case ROUND: do_round(); break;
28036 case ROUNDAWAY: do_roundaway(); break;
28037
28038 case FILECLOSE:
28039 {
28040 FFCore.do_fclose();
28041 break;
28042 }
28043 case FILEFREE:
28044 {
28045 1 FFCore.do_deallocate_file();
28046 1 break;
28047 }
28048 case FILEOWN:
28049 {
28050 1 user_file* f = checkFile(ri->fileref, false);
28051
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(f) own_script_object(f, type, i);
28052 1 break;
28053 }
28054 case FILEISALLOCATED:
28055 {
28056 FFCore.do_file_isallocated();
28057 break;
28058 }
28059 case FILEISVALID:
28060 {
28061 FFCore.do_file_isvalid();
28062 break;
28063 }
28064 case FILEALLOCATE:
28065 {
28066 FFCore.do_allocate_file();
28067 break;
28068 }
28069 case FILEFLUSH:
28070 {
28071 1 FFCore.do_fflush();
28072 1 break;
28073 }
28074 case FILEREMOVE:
28075 {
28076 FFCore.do_fremove();
28077 break;
28078 }
28079 case FILEGETCHAR:
28080 {
28081 FFCore.do_file_getchar();
28082 break;
28083 }
28084 case FILEREWIND:
28085 {
28086 FFCore.do_file_rewind();
28087 break;
28088 }
28089 case FILECLEARERR:
28090 {
28091 FFCore.do_file_clearerr();
28092 break;
28093 }
28094
28095 case FILEOPEN:
28096 {
28097 1 FFCore.do_fopen(false, "rb+");
28098 1 break;
28099 }
28100 case FILECREATE:
28101 {
28102 1 FFCore.do_fopen(false, "wb+");
28103 1 break;
28104 }
28105 case FILEOPENMODE:
28106 {
28107 int32_t arrayptr = get_register(sarg2);
28108 string mode;
28109 ArrayH::getString(arrayptr, mode, 16);
28110 FFCore.do_fopen(false, mode.c_str());
28111 break;
28112 }
28113 case FILEREADSTR:
28114 {
28115 FFCore.do_file_readstring();
28116 break;
28117 }
28118 case FILEWRITESTR:
28119 {
28120 279 FFCore.do_file_writestring();
28121 279 break;
28122 }
28123 case FILEPUTCHAR:
28124 {
28125 FFCore.do_file_putchar();
28126 break;
28127 }
28128 case FILEUNGETCHAR:
28129 {
28130 FFCore.do_file_ungetchar();
28131 break;
28132 }
28133
28134 case FILEREADCHARS:
28135 {
28136 FFCore.do_file_readchars();
28137 break;
28138 }
28139 case FILEREADBYTES:
28140 {
28141 FFCore.do_file_readbytes();
28142 break;
28143 }
28144 case FILEREADINTS:
28145 {
28146 FFCore.do_file_readints();
28147 break;
28148 }
28149 case FILEWRITECHARS:
28150 {
28151 FFCore.do_file_writechars();
28152 break;
28153 }
28154 case FILEWRITEBYTES:
28155 {
28156 FFCore.do_file_writebytes();
28157 break;
28158 }
28159 case FILEWRITEINTS:
28160 {
28161 FFCore.do_file_writeints();
28162 break;
28163 }
28164 case FILESEEK:
28165 {
28166 FFCore.do_file_seek();
28167 break;
28168 }
28169 case FILEGETERROR:
28170 {
28171 FFCore.do_file_geterr();
28172 break;
28173 }
28174 //Directory
28175 case DIRECTORYGET:
28176 {
28177 FFCore.do_directory_get();
28178 break;
28179 }
28180 case DIRECTORYRELOAD:
28181 {
28182 FFCore.do_directory_reload();
28183 break;
28184 }
28185 case DIRECTORYFREE:
28186 {
28187 FFCore.do_directory_free();
28188 break;
28189 }
28190 case DIRECTORYOWN:
28191 {
28192 if(user_dir* dr = checkDir(ri->directoryref))
28193 {
28194 own_script_object(dr, type, i);
28195 }
28196 break;
28197 }
28198 //Stack
28199 case STACKFREE:
28200 {
28201 if(user_stack* st = checkStack(ri->stackref, true))
28202 {
28203 free_script_object(st->id);
28204 }
28205 break;
28206 }
28207 case STACKOWN:
28208 {
28209 if(user_stack* st = checkStack(ri->stackref))
28210 {
28211 own_script_object(st, type, i);
28212 }
28213 break;
28214 }
28215 case STACKCLEAR:
28216 {
28217 if(user_stack* st = checkStack(ri->stackref))
28218 {
28219 st->clearStack();
28220 }
28221 break;
28222 }
28223 case STACKGET:
28224 {
28225 if(user_stack* st = checkStack(ri->stackref, true))
28226 {
28227 int32_t indx = get_register(sarg1); //NOT /10000
28228 set_register(sarg1, st->get(indx)); //NOT *10000
28229 }
28230 else set_register(sarg1, 0L);
28231 break;
28232 }
28233 case STACKSET:
28234 {
28235 if(user_stack* st = checkStack(ri->stackref, true))
28236 {
28237 int32_t indx = get_register(sarg1); //NOT /10000
28238 int32_t val = get_register(sarg2); //NOT /10000
28239 st->set(indx, val); //NOT *10000
28240 }
28241 break;
28242 }
28243 case STACKPOPBACK:
28244 {
28245 if(user_stack* st = checkStack(ri->stackref, true))
28246 {
28247 set_register(sarg1, st->pop_back()); //NOT *10000
28248 }
28249 else set_register(sarg1, 0L);
28250 break;
28251 }
28252 case STACKPOPFRONT:
28253 {
28254 if(user_stack* st = checkStack(ri->stackref, true))
28255 {
28256 set_register(sarg1, st->pop_front()); //NOT *10000
28257 }
28258 else set_register(sarg1, 0L);
28259 break;
28260 }
28261 case STACKPEEKBACK:
28262 {
28263 if(user_stack* st = checkStack(ri->stackref, true))
28264 {
28265 set_register(sarg1, st->peek_back()); //NOT *10000
28266 }
28267 else set_register(sarg1, 0L);
28268 break;
28269 }
28270 case STACKPEEKFRONT:
28271 {
28272 if(user_stack* st = checkStack(ri->stackref, true))
28273 {
28274 set_register(sarg1, st->peek_front()); //NOT *10000
28275 }
28276 else set_register(sarg1, 0L);
28277 break;
28278 }
28279 case STACKPUSHBACK:
28280 {
28281 if(user_stack* st = checkStack(ri->stackref, true))
28282 {
28283 int32_t val = get_register(sarg1); //NOT /10000
28284 st->push_back(val);
28285 }
28286 break;
28287 }
28288 case STACKPUSHFRONT:
28289 {
28290 if(user_stack* st = checkStack(ri->stackref, true))
28291 {
28292 int32_t val = get_register(sarg1); //NOT /10000
28293 st->push_front(val);
28294 }
28295 break;
28296 }
28297
28298 //Module
28299 case MODULEGETIC:
28300 {
28301
28302 int32_t buf_pointer = SH::get_arg(sarg1, false) / 10000;
28303 int32_t element = SH::get_arg(sarg2, false) / 10000;
28304
28305 if ( ((unsigned)element) > 511 )
28306 {
28307 Z_scripterrlog("Illegal itemclass supplied to ZInfo->GetItemClass().\nLegal values are 1 to 511.\n");
28308 }
28309 else
28310 {
28311 char buffer[256] = {0};
28312 strcpy(buffer,ZI.getItemClassName(element));
28313 buffer[255] = '\0';
28314 if(ArrayH::setArray(buf_pointer, buffer) == SH::_Overflow)
28315 {
28316 Z_scripterrlog("Dest string supplied to 'Module->GetItemClass()' is not large enough\n");
28317 }
28318 }
28319
28320 break;
28321 }
28322
28323 //{ Randgen Stuff
28324 case RNGRAND1:
28325 if(user_rng* r = checkRNG(ri->rngref))
28326 {
28327 ri->d[rEXP1] = r->rand(214748, -214748)*10000L;
28328 }
28329 else ri->d[rEXP1] = -10000L;
28330 break;
28331 case RNGRAND2:
28332
1/2
✓ Branch 0 taken 1338 times.
✗ Branch 1 not taken.
1338 if(user_rng* r = checkRNG(ri->rngref))
28333 {
28334 1338 set_register(sarg1,r->rand(get_register(sarg1)/10000L)*10000L);
28335 1338 }
28336 else set_register(sarg1,-10000L);
28337 1338 break;
28338 case RNGRAND3:
28339
1/2
✓ Branch 0 taken 448056 times.
✗ Branch 1 not taken.
448056 if(user_rng* r = checkRNG(ri->rngref))
28340 {
28341 448056 set_register(sarg1,r->rand(get_register(sarg1)/10000L, get_register(sarg2)/10000L)* 10000L);
28342 448056 }
28343 else set_register(sarg1,-10000L);
28344 448056 break;
28345 case RNGLRAND1:
28346 if(user_rng* r = checkRNG(ri->rngref))
28347 {
28348 ri->d[rEXP1] = r->rand();
28349 }
28350 else ri->d[rEXP1] = -10000L;
28351 break;
28352 case RNGLRAND2:
28353 if(user_rng* r = checkRNG(ri->rngref))
28354 {
28355 ri->d[rEXP1] = r->rand(get_register(sarg1));
28356 }
28357 else ri->d[rEXP1] = -10000L;
28358 break;
28359 case RNGLRAND3:
28360 if(user_rng* r = checkRNG(ri->rngref))
28361 {
28362 ri->d[rEXP1] = r->rand(get_register(sarg1), get_register(sarg2));
28363 }
28364 else ri->d[rEXP1] = -10000L;
28365 break;
28366 case RNGSEED:
28367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if(user_rng* r = checkRNG(ri->rngref))
28368 {
28369 73 r->srand(get_register(sarg1));
28370 73 }
28371 73 break;
28372 case RNGRSEED:
28373 if(user_rng* r = checkRNG(ri->rngref))
28374 {
28375 ri->d[rEXP1] = r->srand();
28376 }
28377 else ri->d[rEXP1] = -10000;
28378 break;
28379 case RNGFREE:
28380
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(user_rng* r = checkRNG(ri->rngref, true))
28381 {
28382 6 free_script_object(r->id);
28383 6 }
28384 6 break;
28385 case RNGOWN:
28386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(user_rng* r = checkRNG(ri->rngref, false))
28387 {
28388 8 own_script_object(r, type, i);
28389 8 }
28390 8 break;
28391 //}
28392 case LOADGENERICDATA:
28393 137117 FFCore.do_loadgenericdata(false); break;
28394 case RUNGENFRZSCR:
28395 {
28396 10 bool r = FFCore.runGenericFrozenEngine(word(ri->genericdataref));
28397 10 set_register(sarg1, r ? 10000L : 0L);
28398 10 break;
28399 }
28400
28401 ///----------------------------------------------------------------------------------------------------//
28402
28403 case SUBDATA_GET_NAME:
28404 {
28405 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28406 {
28407 auto aptr = get_register(sarg1);
28408 if(ArrayH::setArray(aptr, sub->name, true) == SH::_Overflow)
28409 Z_scripterrlog("Array supplied to 'subscreendata->GetName()' not large enough,"
28410 " and couldn't be resized!\n");
28411 }
28412 break;
28413 }
28414 case SUBDATA_SET_NAME:
28415 {
28416 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28417 {
28418 auto aptr = get_register(sarg1);
28419 ArrayH::getString(aptr, sub->name);
28420 }
28421 break;
28422 }
28423 case SUBDATA_SWAP_PAGES:
28424 {
28425 ri->subdataref = SH::read_stack(ri->sp+2);
28426 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28427 {
28428 int p1 = SH::read_stack(ri->sp+1) / 10000;
28429 int p2 = SH::read_stack(ri->sp+0) / 10000;
28430 if(unsigned(p1) >= sub->pages.size())
28431 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p1);
28432 else if(unsigned(p2) >= sub->pages.size())
28433 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p2);
28434 else sub->swap_pages(p1,p2);
28435 }
28436 break;
28437 }
28438 case SUBPAGE_SWAP_WIDG:
28439 {
28440 ri->subpageref = SH::read_stack(ri->sp+2);
28441 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28442 {
28443 int p1 = SH::read_stack(ri->sp+1) / 10000;
28444 int p2 = SH::read_stack(ri->sp+0) / 10000;
28445 if(unsigned(p1) >= pg->size())
28446 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p1);
28447 else if(unsigned(p2) >= pg->size())
28448 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p2);
28449 else pg->swap_widg(p1,p2);
28450 }
28451 break;
28452 }
28453 case SUBPAGE_FIND_WIDGET:
28454 {
28455 14870 ri->d[rEXP1] = 0;
28456 14870 ri->subpageref = SH::read_stack(ri->sp+1);
28457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(SubscrPage* pg = checkSubPage(ri->subpageref, sstACTIVE))
28458 {
28459 14870 int cursorpos = SH::read_stack(ri->sp+0) / 10000;
28460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(auto* widg = pg->get_widg_pos(cursorpos,false))
28461 {
28462 14870 auto q = pg->widget_index(widg);
28463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(q > -1)
28464 {
28465 44610 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28466 44610 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
28467 14870 }
28468 14870 }
28469 14870 }
28470 14870 break;
28471 }
28472 case SUBPAGE_FIND_WIDGET_BY_LABEL:
28473 {
28474 17877 ri->d[rEXP1] = 0;
28475 17877 ri->subpageref = SH::read_stack(ri->sp+1);
28476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17877 times.
17877 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28477 {
28478 17877 int aptr = SH::read_stack(ri->sp+0);
28479 17877 std::string lbl;
28480
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 ArrayH::getString(aptr, lbl);
28481
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 if(lbl.size())
28482 {
28483
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 auto q = pg->find_label_index(lbl);
28484
2/2
✓ Branch 0 taken 5703 times.
✓ Branch 1 taken 12174 times.
17877 if(q > -1)
28485 {
28486 36522 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28487 36522 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
28488 12174 }
28489 17877 }
28490 17877 }
28491 17877 break;
28492 }
28493 case SUBPAGE_MOVE_SEL:
28494 {
28495 #define SUBSEL_FLAG_NO_NONEQUIP 0x01
28496 #define SUBSEL_FLAG_NEED_ITEM 0x02
28497 ri->subpageref = SH::read_stack(ri->sp+3);
28498 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28499 {
28500 int flags = SH::read_stack(ri->sp+0) / 10000;
28501 int dir = SH::read_stack(ri->sp+1) / 10000;
28502 int pos = SH::read_stack(ri->sp+2) / 10000;
28503 switch(dir)
28504 {
28505 case up:
28506 dir = SEL_UP;
28507 break;
28508 case down:
28509 dir = SEL_DOWN;
28510 break;
28511 case left:
28512 dir = SEL_LEFT;
28513 break;
28514 case right: default:
28515 dir = SEL_RIGHT;
28516 break;
28517 }
28518
28519 auto newpos = pg->movepos_legacy(dir, (pos<<8)|pg->getIndex(),
28520 255, 255, 255, flags&SUBSEL_FLAG_NO_NONEQUIP,
28521 flags&SUBSEL_FLAG_NEED_ITEM, true) >> 8;
28522 ri->d[rEXP1] = 10000*newpos;
28523 }
28524 break;
28525 }
28526 case SUBPAGE_NEW_WIDG:
28527 {
28528 ri->subpageref = SH::read_stack(ri->sp+1);
28529 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28530 {
28531 if(pg->size() == 0x2000)
28532 break; //Page is full!
28533 int ty = SH::read_stack(ri->sp+0) / 10000;
28534 if(auto* widg = SubscrWidget::newType(ty))
28535 {
28536 widg->posflags = sspUP | sspDOWN | sspSCROLLING;
28537 widg->w = 1;
28538 widg->h = 1;
28539 pg->push_back(widg);
28540 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28541 ri->d[rEXP1] = get_subref(sub,ty,pgid,pg->size()-1);
28542 }
28543 else Z_scripterrlog("Invalid type %d passed to subscreenpage->CreateWidget()\n",ty);
28544 }
28545 break;
28546 }
28547 case SUBPAGE_DELETE:
28548 {
28549 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28550 {
28551 auto [sub,_ty] = load_subdata(ri->subpageref);
28552 sub->delete_page(pg->getIndex());
28553 }
28554 break;
28555 }
28556 case SUBWIDG_GET_SELTEXT_OVERRIDE:
28557 {
28558 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28559 {
28560 auto aptr = get_register(sarg1);
28561 if(ArrayH::setArray(aptr, widg->override_text, true) == SH::_Overflow)
28562 Z_scripterrlog("Array supplied to 'subscreenwidget->GetSelTextOverride()' not large enough,"
28563 " and couldn't be resized!\n");
28564 }
28565 break;
28566 }
28567 case SUBWIDG_SET_SELTEXT_OVERRIDE:
28568 {
28569 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28570 {
28571 auto aptr = get_register(sarg1);
28572 ArrayH::getString(aptr, widg->override_text);
28573 }
28574 break;
28575 }
28576 case SUBWIDG_GET_LABEL:
28577 {
28578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 828 times.
828 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28579 {
28580 828 auto aptr = get_register(sarg1);
28581
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(ArrayH::setArray(aptr, widg->label, true) == SH::_Overflow)
28582 Z_scripterrlog("Array supplied to 'subscreenwidget->GetLabel()' not large enough,"
28583 " and couldn't be resized!\n");
28584 828 }
28585 828 break;
28586 }
28587 case SUBWIDG_SET_LABEL:
28588 {
28589 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28590 {
28591 auto aptr = get_register(sarg1);
28592 ArrayH::getString(aptr, widg->label);
28593 }
28594 break;
28595 }
28596 case SUBWIDG_CHECK_CONDITIONS:
28597 {
28598 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28599 {
28600 set_register(sarg1, widg->check_conditions() ? 10000 : 0);
28601 }
28602 break;
28603 }
28604 case SUBWIDG_CHECK_VISIBLE:
28605 {
28606 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28607 {
28608 extern int current_subscr_pos;
28609 set_register(sarg1, widg->visible(current_subscr_pos, game->should_show_time()) ? 10000 : 0);
28610 }
28611 break;
28612 }
28613 case SUBWIDG_TY_GETTEXT:
28614 {
28615 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28616 {
28617 std::string const* str = nullptr;
28618 byte ty = widg->getType();
28619 switch(ty)
28620 {
28621 case widgTEXT:
28622 str = &((SW_Text*)widg)->text;
28623 break;
28624 case widgTEXTBOX:
28625 str = &((SW_TextBox*)widg)->text;
28626 break;
28627 default:
28628 bad_subwidg_type(true, ty);
28629 break;
28630 }
28631 if(str)
28632 {
28633 auto aptr = get_register(sarg1);
28634 if(ArrayH::setArray(aptr, *str, true) == SH::_Overflow)
28635 Z_scripterrlog("Array supplied to 'subscreenwidget->GetText()' not large enough,"
28636 " and couldn't be resized!\n");
28637 }
28638 }
28639 break;
28640 }
28641 case SUBWIDG_TY_SETTEXT:
28642 {
28643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76234 times.
76234 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28644 {
28645 76234 std::string* str = nullptr;
28646 76234 byte ty = widg->getType();
28647
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 68852 times.
✓ Branch 2 taken 7382 times.
76234 switch(ty)
28648 {
28649 case widgTEXT:
28650 68852 str = &((SW_Text*)widg)->text;
28651 68852 break;
28652 case widgTEXTBOX:
28653 7382 str = &((SW_TextBox*)widg)->text;
28654 7382 break;
28655 default:
28656 bad_subwidg_type(true, ty);
28657 break;
28658 }
28659
1/2
✓ Branch 0 taken 76234 times.
✗ Branch 1 not taken.
76234 if(str)
28660 {
28661 76234 auto aptr = get_register(sarg1);
28662 76234 ArrayH::getString(aptr, *str);
28663 76234 }
28664 76234 }
28665 76234 break;
28666 }
28667
28668 case COMBOD_GET_TRIGGER:
28669 {
28670 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
28671 {
28672 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
28673 }
28674 else
28675 {
28676 auto aptr = get_register(sarg1) / 10000;
28677 string name;
28678 ArrayH::getString(aptr, name, 256);
28679 newcombo const& cmb = combobuf[ri->combosref];
28680 int32_t ret = 0;
28681 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
28682 {
28683 if(cmb.triggers[idx].label == name)
28684 {
28685 ret = dword(ri->combosref) | (dword(idx)<<24);
28686 break;
28687 }
28688 }
28689
28690 set_register(sarg1, ret);
28691 }
28692 break;
28693 }
28694 case CMBTRIG_GET_LABEL:
28695 {
28696 if(auto* trig = get_combo_trigger(ri->combotrigref))
28697 {
28698 auto aptr = get_register(sarg1) / 10000;
28699 if(ArrayH::setArray(aptr, trig->label, true) == SH::_Overflow)
28700 Z_scripterrlog("Array supplied to 'combotrigger->GetLabel()' not large enough,"
28701 " and couldn't be resized!\n");
28702 }
28703 break;
28704 }
28705 case CMBTRIG_SET_LABEL:
28706 {
28707 if (auto* trig = get_combo_trigger(ri->combotrigref))
28708 {
28709 auto aptr = get_register(sarg1) / 10000;
28710 ArrayH::getString(aptr, trig->label);
28711 }
28712 break;
28713 }
28714
28715 case REF_INC:
28716 {
28717 30120 int offset = ri->d[rSFRAME] + sarg1;
28718
1/2
✓ Branch 0 taken 30120 times.
✗ Branch 1 not taken.
30120 if (!ri->stack_pos_is_object.contains(offset))
28719 {
28720 assert(false);
28721 break;
28722 }
28723
28724 30120 uint32_t id = SH::read_stack(offset);
28725 30120 script_object_ref_inc(id);
28726 30120 break;
28727 }
28728 case REF_DEC:
28729 {
28730 int offset = ri->d[rSFRAME] + sarg1;
28731 if (!ri->stack_pos_is_object.contains(offset))
28732 {
28733 assert(false);
28734 break;
28735 }
28736
28737 uint32_t id = SH::read_stack(offset);
28738 script_object_ref_dec(id);
28739 break;
28740 }
28741 case REF_AUTORELEASE:
28742 {
28743 67629 uint32_t id = get_register(sarg1);
28744
4/4
✓ Branch 0 taken 63379 times.
✓ Branch 1 taken 4250 times.
✓ Branch 2 taken 8871 times.
✓ Branch 3 taken 54508 times.
67629 if (id && !util::contains(script_object_autorelease_pool, id))
28745 {
28746 54508 script_object_autorelease_pool.push_back(id);
28747
1/2
✓ Branch 0 taken 54508 times.
✗ Branch 1 not taken.
54508 if (auto object = get_script_object_checked(id))
28748 54508 object->ref_count++;
28749 54508 }
28750 67629 break;
28751 }
28752 case REF_COUNT:
28753 {
28754
1/2
✓ Branch 0 taken 1374 times.
✗ Branch 1 not taken.
1374 if (!use_testingst_start)
28755 {
28756 scripting_log_error_with_context("This function can only be used in test mode");
28757 break;
28758 }
28759
28760 1374 uint32_t id = get_register(sarg1);
28761 1374 auto object = get_script_object(id);
28762
2/2
✓ Branch 0 taken 1359 times.
✓ Branch 1 taken 15 times.
1374 int count = object ? object->ref_count : -1;
28763 1374 set_register(sarg1, count);
28764 1374 break;
28765 }
28766 case MARK_TYPE_STACK:
28767 {
28768 30120 int offset = ri->d[rSFRAME] + sarg2;
28769
1/2
✓ Branch 0 taken 30120 times.
✗ Branch 1 not taken.
30120 if (offset < 0 || offset >= MAX_STACK_SIZE)
28770 {
28771 assert(false);
28772 break;
28773 }
28774
1/2
✓ Branch 0 taken 30120 times.
✗ Branch 1 not taken.
30120 if (sarg1 < 0 || sarg1 > 1)
28775 {
28776 assert(false);
28777 break;
28778 }
28779
28780
1/2
✓ Branch 0 taken 30120 times.
✗ Branch 1 not taken.
30120 if (sarg1)
28781 30120 ri->stack_pos_is_object.insert(offset);
28782 else
28783 ri->stack_pos_is_object.erase(offset);
28784 30120 break;
28785 }
28786 case MARK_TYPE_REG:
28787 {
28788 2210 markRegisterType(sarg1, sarg2);
28789 2210 break;
28790 }
28791 case REF_REMOVE:
28792 {
28793 95901 int offset = ri->d[rSFRAME] + sarg1;
28794 95901 script_remove_object_ref(offset);
28795 95901 break;
28796 }
28797 case GC:
28798 {
28799
1/2
✓ Branch 0 taken 226 times.
✗ Branch 1 not taken.
226 if (!use_testingst_start)
28800 {
28801 Z_error_fatal("GC can only be used in test mode\n");
28802 break;
28803 }
28804
28805 226 run_gc();
28806 226 break;
28807 }
28808 case SET_OBJECT:
28809 {
28810
1/2
✓ Branch 0 taken 1654 times.
✗ Branch 1 not taken.
1654 if (!(sarg1 >= GD(0) && sarg1 <= GD(MAX_SCRIPT_REGISTERS)))
28811 {
28812 assert(false);
28813 break;
28814 }
28815
28816 1654 int value = get_register(sarg2);
28817 1654 int index = sarg1-GD(0);
28818
1/2
✓ Branch 0 taken 1654 times.
✗ Branch 1 not taken.
1654 assert(game->global_d_types[index] != script_object_type::none);
28819 1654 script_object_ref_inc(value);
28820 1654 script_object_ref_dec(game->global_d[index]);
28821 1654 game->global_d[index] = value;
28822 1654 break;
28823 }
28824 case LOAD_INTERNAL_ARRAY:
28825 {
28826 4 do_load_internal_array();
28827 4 break;
28828 }
28829 case LOAD_INTERNAL_ARRAY_REF:
28830 {
28831 22 do_load_internal_array_ref();
28832 22 break;
28833 }
28834
28835 default:
28836 {
28837
1/2
✓ Branch 0 taken 1665452 times.
✗ Branch 1 not taken.
1665452 if (auto r = scripting_engine_run_command(scommand))
28838 {
28839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1665452 times.
1665452 if (*r != RUNSCRIPT_OK)
28840 return *r;
28841 1665452 break;
28842 }
28843
28844 scripting_log_error_with_context("Invalid ZASM command {} reached; terminating", scommand);
28845 hit_invalid_zasm = true;
28846 scommand = 0xFFFF;
28847 break;
28848 }
28849 }
28850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10120612575 times.
10120612575 if(earlyretval == RUNSCRIPT_SELFDELETE)
28851 {
28852 earlyretval = -1;
28853 return RUNSCRIPT_SELFDELETE;
28854 }
28855
2/2
✓ Branch 0 taken 10120612573 times.
✓ Branch 1 taken 2 times.
10120612575 if (ri->overflow)
28856 {
28857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (old_script_funcrun)
28858 return RUNSCRIPT_OK;
28859 2 scommand = 0xFFFF;
28860 2 }
28861
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10120612575 times.
10120612575 if(hit_invalid_zasm) break;
28862
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 10120612575 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
10120612575 if(old_script_funcrun && (ri->pc == MAX_PC || scommand == RETURN))
28863 return RUNSCRIPT_OK;
28864
28865
2/2
✓ Branch 0 taken 10113249275 times.
✓ Branch 1 taken 7363300 times.
10120612575 if (type == ScriptType::Combo)
28866 {
28867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7363300 times.
7363300 if(combopos_modified == i)
28868 {
28869 //Combo changed! Abort script!
28870 return RUNSCRIPT_OK;
28871 }
28872 7363300 }
28873
2/2
✓ Branch 0 taken 83542 times.
✓ Branch 1 taken 10120529033 times.
10120612575 if(scommand != 0xFFFF)
28874 {
28875
2/2
✓ Branch 0 taken 9407768175 times.
✓ Branch 1 taken 712760858 times.
10120529033 if(increment) ri->pc++;
28876 712760858 else increment = true;
28877
1/2
✓ Branch 0 taken 10120529033 times.
✗ Branch 1 not taken.
10120529033 if ( ri->pc == MAX_PC ) //rolled over from overflow?
28878 {
28879 Z_scripterrlog("Script PC overflow! Too many ZASM lines?\n");
28880 ri->pc = curscript->pc;
28881 scommand = 0xFFFF;
28882 }
28883 10120529033 }
28884
28885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10120612575 times.
10120612575 if(earlyretval > -1) //Should this be below the 'commands_run += 1'? Unsure. -Em
28886 {
28887 auto v = earlyretval;
28888 earlyretval = -1;
28889 return earlyretval;
28890 }
28891
28892 // If running a JIT compiled script, we're only here to do a few commands.
28893 10120612575 commands_run += 1;
28894
4/4
✓ Branch 0 taken 1055756562 times.
✓ Branch 1 taken 9064856013 times.
✓ Branch 2 taken 1047545485 times.
✓ Branch 3 taken 8211077 times.
10120612575 if (is_jitted && commands_run == jitted_uncompiled_command_count)
28895 {
28896 1047545485 current_zasm_command=(ASM_DEFINE)0;
28897 1047545485 break;
28898 }
28899 }
28900
2/2
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 1074108888 times.
1074109698 if(script_funcrun) return RUNSCRIPT_OK;
28901
28902
2/2
✓ Branch 0 taken 1074108858 times.
✓ Branch 1 taken 30 times.
1074108888 if(!scriptCanSave)
28903 30 scriptCanSave=true;
28904
28905
2/2
✓ Branch 0 taken 1068060448 times.
✓ Branch 1 taken 6048440 times.
1074108888 if(scommand == WAITDRAW)
28906 {
28907
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 6032158 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16282 times.
6048440 switch(type)
28908 {
28909 case ScriptType::Global:
28910 case ScriptType::Hero:
28911 case ScriptType::DMap:
28912 case ScriptType::OnMap:
28913 case ScriptType::ScriptedPassiveSubscreen:
28914 case ScriptType::ScriptedActiveSubscreen:
28915 case ScriptType::Screen:
28916 case ScriptType::Combo:
28917 case ScriptType::NPC:
28918 case ScriptType::Lwpn:
28919 case ScriptType::Ewpn:
28920 case ScriptType::ItemSprite:
28921 6032158 FFCore.waitdraw(type, i) = true;
28922 6032158 break;
28923
28924 case ScriptType::Item:
28925 {
28926 if (!get_qr(qr_NOITEMWAITDRAW))
28927 {
28928 FFCore.waitdraw(ScriptType::Item, i) = true;
28929 }
28930 break;
28931 }
28932
28933 case ScriptType::FFC:
28934 {
28935
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 15061 times.
16282 if ( !(get_qr(qr_NOFFCWAITDRAW)) )
28936 {
28937 15061 FFCore.waitdraw(ScriptType::FFC, i) = true;
28938 15061 }
28939 else
28940 {
28941 1221 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", "ffc, with Script Rule 'No FFC Waitdraw() enabled!");
28942 }
28943 16282 break;
28944 }
28945
28946 case ScriptType::Generic:
28947 case ScriptType::GenericFrozen:
28948 case ScriptType::EngineSubscreen:
28949 //No Waitdraw
28950 break;
28951
28952 default:
28953 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", ScriptTypeToString(type));
28954 break;
28955 }
28956 6048440 }
28957
28958
2/2
✓ Branch 0 taken 82757 times.
✓ Branch 1 taken 1074026131 times.
1074108888 if(scommand == 0xFFFF) //Quit/command list end reached/bad command
28959 {
28960 82757 script_exit_cleanup(no_dealloc);
28961 82757 return RUNSCRIPT_STOPPED;
28962 }
28963 else
28964 1074026131 ri->pc++;
28965
28966
2/2
✓ Branch 0 taken 24007162 times.
✓ Branch 1 taken 1050018969 times.
1074026131 if(jit_waiting_nop)
28967 24007162 return RUNSCRIPT_STOPPED;
28968
28969 1050018969 return RUNSCRIPT_OK;
28970 1074110259 }
28971
28972 1964 script_data* load_scrdata(ScriptType type, word script, int32_t i)
28973 {
28974
2/15
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 344 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1620 times.
✗ Branch 14 not taken.
1964 switch(type)
28975 {
28976 case ScriptType::FFC:
28977 return ffscripts[script];
28978 case ScriptType::NPC:
28979 return guyscripts[guys.getByUID(i)->script];
28980 case ScriptType::Lwpn:
28981 return lwpnscripts[Lwpns.getByUID(i)->script];
28982 case ScriptType::Ewpn:
28983 return ewpnscripts[Ewpns.getByUID(i)->script];
28984 case ScriptType::ItemSprite:
28985 return itemspritescripts[items.getByUID(i)->script];
28986 case ScriptType::Item:
28987 return itemscripts[script];
28988 case ScriptType::Global:
28989 return globalscripts[script];
28990 case ScriptType::Generic:
28991 case ScriptType::GenericFrozen:
28992 1620 return genericscripts[script];
28993 case ScriptType::Hero:
28994 return playerscripts[script];
28995 case ScriptType::DMap:
28996 return dmapscripts[script];
28997 case ScriptType::OnMap:
28998 case ScriptType::ScriptedActiveSubscreen:
28999 case ScriptType::ScriptedPassiveSubscreen:
29000 return dmapscripts[script];
29001 case ScriptType::Screen:
29002 return screenscripts[script];
29003 case ScriptType::Combo:
29004 return comboscripts[script];
29005 case ScriptType::EngineSubscreen:
29006 return subscreenscripts[script];
29007 }
29008 344 return nullptr;
29009 1964 }
29010
29011 //This keeps ffc scripts running beyond the first frame.
29012 14437189 int32_t ffscript_engine(const bool preload)
29013 {
29014
2/2
✓ Branch 0 taken 14402369 times.
✓ Branch 1 taken 34820 times.
14437189 if(preload)
29015 {
29016 34820 throwGenScriptEvent(GENSCR_EVENT_FFC_PRELOAD);
29017 34820 handle_region_load_trigger();
29018 34820 }
29019
29020
6/6
✓ Branch 0 taken 14434603 times.
✓ Branch 1 taken 2586 times.
✓ Branch 2 taken 1835498 times.
✓ Branch 3 taken 12599105 times.
✓ Branch 4 taken 1824286 times.
✓ Branch 5 taken 11212 times.
14437189 if (!FFCore.system_suspend[susptSCREENSCRIPTS] && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !get_qr(qr_ZS_OLD_SUSPEND_FFC))
29021 {
29022 22424 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
29023
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 11194 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 11176 times.
11212 if ((preload && scr->preloadscript) || !preload)
29024 {
29025
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11194 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11194 if (scr->script > 0 && FFCore.doscript(ScriptType::Screen, scr->screen))
29026 {
29027 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
29028 }
29029 11194 }
29030 11212 });
29031 11212 }
29032
29033
2/2
✓ Branch 0 taken 2586 times.
✓ Branch 1 taken 14434603 times.
14437189 if (!FFCore.system_suspend[susptFFCSCRIPTS])
29034 {
29035 //intentional it's for compatability
29036
4/4
✓ Branch 0 taken 1835498 times.
✓ Branch 1 taken 12599105 times.
✓ Branch 2 taken 11212 times.
✓ Branch 3 taken 1824286 times.
14434603 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && get_qr(qr_ZS_OLD_SUSPEND_FFC))
29037 {
29038 4037648 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
29039
4/4
✓ Branch 0 taken 5147 times.
✓ Branch 1 taken 2208215 times.
✓ Branch 2 taken 5068 times.
✓ Branch 3 taken 2203147 times.
2213362 if ((preload && scr->preloadscript) || !preload)
29040 {
29041
3/4
✓ Branch 0 taken 50436 times.
✓ Branch 1 taken 2157858 times.
✓ Branch 2 taken 50436 times.
✗ Branch 3 not taken.
2208294 if (scr->script > 0 && FFCore.doscript(ScriptType::Screen, scr->screen))
29042 {
29043 50436 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
29044 50436 }
29045 2208294 }
29046 2213362 });
29047 1824286 }
29048
29049 457970449 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
29050
2/2
✓ Branch 0 taken 11252376 times.
✓ Branch 1 taken 432283470 times.
443535846 if(ffc_handle.ffc->script == 0)
29051 432283470 return;
29052
29053
4/4
✓ Branch 0 taken 12919 times.
✓ Branch 1 taken 11239457 times.
✓ Branch 2 taken 10119 times.
✓ Branch 3 taken 2800 times.
11252376 if(preload && !(ffc_handle.ffc->flags&ffc_preload))
29054 10119 return;
29055
29056
4/4
✓ Branch 0 taken 11237698 times.
✓ Branch 1 taken 4559 times.
✓ Branch 2 taken 11152617 times.
✓ Branch 3 taken 85081 times.
11242257 if((ffc_handle.ffc->flags&ffc_ignoreholdup)==0 && Hero.getHoldClk()>0)
29057 85081 return;
29058
29059 11157176 ZScriptVersion::RunScript(ScriptType::FFC, ffc_handle.ffc->script, ffc_handle.id);
29060 443535846 });
29061 14434603 }
29062
29063
29064 14437189 return 0;
29065 }
29066
29067
29068
29069 ///----------------------------------------------------------------------------------------------------
29070
29071 422 void FFScript::user_files_init()
29072 {
29073 422 user_files.clear();
29074 422 }
29075
29076 422 void FFScript::user_dirs_init()
29077 {
29078 422 user_dirs.clear();
29079 422 }
29080 422 void FFScript::user_objects_init()
29081 {
29082 422 ::user_object_init();
29083 422 }
29084
29085 422 void FFScript::user_stacks_init()
29086 {
29087 422 user_stacks.clear();
29088 422 }
29089
29090 1116 void FFScript::user_rng_init()
29091 {
29092 1116 user_rngs.clear();
29093
2/2
✓ Branch 0 taken 285696 times.
✓ Branch 1 taken 1116 times.
286812 for(int32_t q = 0; q < MAX_USER_RNGS; ++q)
29094 {
29095 285696 replay_register_rng(&script_rnggens[q]);
29096
29097 // Just to seed it.
29098 285696 user_rng rng;
29099 285696 rng.set_gen(&script_rnggens[q]);
29100 285696 }
29101 1116 }
29102
29103 422 void FFScript::user_paldata_init()
29104 {
29105 422 user_paldatas.clear();
29106 422 }
29107
29108 422 void FFScript::user_websockets_init()
29109 {
29110 422 websocket_init();
29111 422 }
29112
29113 612 void FFScript::script_arrays_init()
29114 {
29115 612 script_arrays.clear();
29116 612 }
29117
29118 // Gotten from 'https://fileinfo.com/filetypes/executable'
29119
187/376
✓ Branch 0 taken 412 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 412 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 412 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 412 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 412 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 412 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 412 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 412 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 412 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 412 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 412 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 412 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 412 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 412 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 412 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 412 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 412 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 412 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 412 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 412 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 412 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 412 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 412 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 412 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 412 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 412 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 412 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 412 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 412 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 412 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 412 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 412 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 412 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 412 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 412 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 412 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 412 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 412 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 412 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 412 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 412 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 412 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 412 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 412 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 412 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 412 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 412 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 412 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 412 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 412 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 412 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 412 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 412 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 412 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 412 times.
✗ Branch 109 not taken.
✓ Branch 110 taken 412 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 412 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 412 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 412 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 412 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 412 times.
✗ Branch 121 not taken.
✓ Branch 122 taken 412 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 412 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 412 times.
✗ Branch 127 not taken.
✓ Branch 128 taken 412 times.
✗ Branch 129 not taken.
✓ Branch 130 taken 412 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 412 times.
✗ Branch 133 not taken.
✓ Branch 134 taken 412 times.
✗ Branch 135 not taken.
✓ Branch 136 taken 412 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 412 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 412 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 412 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 412 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 412 times.
✗ Branch 147 not taken.
✓ Branch 148 taken 412 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 412 times.
✗ Branch 151 not taken.
✓ Branch 152 taken 412 times.
✗ Branch 153 not taken.
✓ Branch 154 taken 412 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 412 times.
✗ Branch 157 not taken.
✓ Branch 158 taken 412 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 412 times.
✗ Branch 161 not taken.
✓ Branch 162 taken 412 times.
✗ Branch 163 not taken.
✓ Branch 164 taken 412 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 412 times.
✗ Branch 167 not taken.
✓ Branch 168 taken 412 times.
✗ Branch 169 not taken.
✓ Branch 170 taken 412 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 412 times.
✗ Branch 173 not taken.
✓ Branch 174 taken 412 times.
✗ Branch 175 not taken.
✓ Branch 176 taken 412 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 412 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 412 times.
✗ Branch 181 not taken.
✓ Branch 182 taken 412 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 412 times.
✗ Branch 185 not taken.
✓ Branch 186 taken 412 times.
✗ Branch 187 not taken.
✓ Branch 188 taken 412 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 412 times.
✗ Branch 191 not taken.
✓ Branch 192 taken 412 times.
✗ Branch 193 not taken.
✓ Branch 194 taken 412 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 412 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 412 times.
✗ Branch 199 not taken.
✓ Branch 200 taken 412 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 412 times.
✗ Branch 203 not taken.
✓ Branch 204 taken 412 times.
✗ Branch 205 not taken.
✓ Branch 206 taken 412 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 412 times.
✗ Branch 209 not taken.
✓ Branch 210 taken 412 times.
✗ Branch 211 not taken.
✓ Branch 212 taken 412 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 412 times.
✗ Branch 215 not taken.
✓ Branch 216 taken 412 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 412 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 412 times.
✗ Branch 221 not taken.
✓ Branch 222 taken 412 times.
✗ Branch 223 not taken.
✓ Branch 224 taken 412 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 412 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 412 times.
✗ Branch 229 not taken.
✓ Branch 230 taken 412 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 412 times.
✗ Branch 233 not taken.
✓ Branch 234 taken 412 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 412 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 412 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 412 times.
✗ Branch 241 not taken.
✓ Branch 242 taken 412 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 412 times.
✗ Branch 245 not taken.
✓ Branch 246 taken 412 times.
✗ Branch 247 not taken.
✓ Branch 248 taken 412 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 412 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 412 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 412 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 412 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 412 times.
✗ Branch 259 not taken.
✓ Branch 260 taken 412 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 412 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 412 times.
✗ Branch 265 not taken.
✓ Branch 266 taken 412 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 412 times.
✗ Branch 269 not taken.
✓ Branch 270 taken 412 times.
✗ Branch 271 not taken.
✓ Branch 272 taken 412 times.
✗ Branch 273 not taken.
✓ Branch 274 taken 412 times.
✗ Branch 275 not taken.
✓ Branch 276 taken 412 times.
✗ Branch 277 not taken.
✓ Branch 278 taken 412 times.
✗ Branch 279 not taken.
✓ Branch 280 taken 412 times.
✗ Branch 281 not taken.
✓ Branch 282 taken 412 times.
✗ Branch 283 not taken.
✓ Branch 284 taken 412 times.
✗ Branch 285 not taken.
✓ Branch 286 taken 412 times.
✗ Branch 287 not taken.
✓ Branch 288 taken 412 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 412 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 412 times.
✗ Branch 293 not taken.
✓ Branch 294 taken 412 times.
✗ Branch 295 not taken.
✓ Branch 296 taken 412 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 412 times.
✗ Branch 299 not taken.
✓ Branch 300 taken 412 times.
✗ Branch 301 not taken.
✓ Branch 302 taken 412 times.
✗ Branch 303 not taken.
✓ Branch 304 taken 412 times.
✗ Branch 305 not taken.
✓ Branch 306 taken 412 times.
✗ Branch 307 not taken.
✓ Branch 308 taken 412 times.
✗ Branch 309 not taken.
✓ Branch 310 taken 412 times.
✗ Branch 311 not taken.
✓ Branch 312 taken 412 times.
✗ Branch 313 not taken.
✓ Branch 314 taken 412 times.
✗ Branch 315 not taken.
✓ Branch 316 taken 412 times.
✗ Branch 317 not taken.
✓ Branch 318 taken 412 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 412 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 412 times.
✗ Branch 323 not taken.
✓ Branch 324 taken 412 times.
✗ Branch 325 not taken.
✓ Branch 326 taken 412 times.
✗ Branch 327 not taken.
✓ Branch 328 taken 412 times.
✗ Branch 329 not taken.
✓ Branch 330 taken 412 times.
✗ Branch 331 not taken.
✓ Branch 332 taken 412 times.
✗ Branch 333 not taken.
✓ Branch 334 taken 412 times.
✗ Branch 335 not taken.
✓ Branch 336 taken 412 times.
✗ Branch 337 not taken.
✓ Branch 338 taken 412 times.
✗ Branch 339 not taken.
✓ Branch 340 taken 412 times.
✗ Branch 341 not taken.
✓ Branch 342 taken 412 times.
✗ Branch 343 not taken.
✓ Branch 344 taken 412 times.
✗ Branch 345 not taken.
✓ Branch 346 taken 412 times.
✗ Branch 347 not taken.
✓ Branch 348 taken 412 times.
✗ Branch 349 not taken.
✓ Branch 350 taken 412 times.
✗ Branch 351 not taken.
✓ Branch 352 taken 412 times.
✗ Branch 353 not taken.
✓ Branch 354 taken 412 times.
✗ Branch 355 not taken.
✓ Branch 356 taken 412 times.
✗ Branch 357 not taken.
✓ Branch 358 taken 412 times.
✗ Branch 359 not taken.
✓ Branch 360 taken 412 times.
✗ Branch 361 not taken.
✓ Branch 362 taken 412 times.
✗ Branch 363 not taken.
✓ Branch 364 taken 412 times.
✗ Branch 365 not taken.
✓ Branch 366 taken 412 times.
✗ Branch 367 not taken.
✓ Branch 368 taken 412 times.
✗ Branch 369 not taken.
✓ Branch 370 taken 412 times.
✗ Branch 371 not taken.
✓ Branch 372 taken 412 times.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
412 static std::set<std::string> banned_extensions = {".xlm",".caction",".8ck", ".actc",".a6p", ".m3g",".run",".workflow",".otm",".apk",".fxp",".73k",".0xe",".exe",".cmd",".jsx",".scar",".wcm",".jar",".ebs2",".ipa",".xap",".ba_",".ac",".bin",".vlx",".icd",".elf",".xbap",".89k",".widget",".a7r",".ex_",".zl9",".cgi",".scr",".coffee",".ahk",".plsc",".air",".ear",".app",".scptd",".xys",".hms",".cyw",".ebm",".pwc",".xqt",".msl",".seed",".vexe",".ebs",".mcr",".gpu",".celx",".wsh",".frs",".vxp",".action",".com",".out",".gadget",".command",".script",".rfu",".tcp",".widget",".ex4",".bat",".cof",".phar",".rxe",".scb",".ms",".isu",".fas",".mlx",".gpe",".mcr",".mrp",".u3p",".js",".acr",".epk",".exe1",".jsf",".rbf",".rgs",".vpm",".ecf",".hta",".dld",".applescript",".prg",".pyc",".spr",".nexe",".server",".appimage",".pyo",".dek",".mrc",".fpi",".rpj",".iim",".vbs",".pif",".mel",".scpt",".csh",".paf",".ws",".mm",".acc",".ex5",".mac",".plx",".snap",".ps1",".vdo",".mxe",".gs",".osx",".sct",".wiz",".x86",".e_e",".fky",".prg",".fas",".azw2",".actm",".cel",".tiapp",".thm",".kix",".wsf",".vbe",".lo",".ls",".tms",".ezs",".ds",".n",".esh",".vbscript",".arscript",".qit",".pex",".dxl",".wpm",".s2a",".sca",".prc",".shb",".rbx",".jse",".beam",".udf",".mem",".kx",".ksh",".rox",".upx",".ms",".mam",".btm",".es",".asb",".ipf",".mio",".sbs",".hpf",".ita",".eham",".ezt",".dmc",".qpx",".ore",".ncl",".exopc",".smm",".pvd",".ham",".wpk"};
29120
29121 // If the path is valid, returns an absolute path under the quest "Files" directory.
29122 2 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file)
29123 {
29124 // First check for non-portable path characters.
29125 static const char* invalid_chars = "<>|?*&^$#\":";
29126
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (auto index = user_path.find_first_of(invalid_chars) != string::npos)
29127 {
29128 return make_unexpected(fmt::format("Bad path: {} - invalid character {}", user_path, user_path[index]));
29129 }
29130
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 2 times.
56 for (char c : user_path)
29131 {
29132
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if (c < 32)
29133 return make_unexpected(fmt::format("Bad path: {} - invalid control character {:#x}", user_path, c));
29134 }
29135
29136 // Any leading slashes are ignored.
29137 // This makes path always relative.
29138 2 const char* path = user_path.c_str();
29139
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 while (path[0] == '/' || path[0] == '\\')
29140 path++;
29141
29142 // Normalize `user_path` and check if it accesses a parent path.
29143
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto files_path = fs::absolute(fs::path(qst_files_path));
29144
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto normalized_path = fs::path(path).lexically_normal();
29145
5/12
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4 if (!normalized_path.empty() && normalized_path.begin()->string() == "..")
29146 {
29147 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {} (too many ..?)",
29148 path, normalized_path.string(), files_path.string()));
29149 }
29150
29151
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto resolved_path = files_path / normalized_path;
29152
29153 // The above should be enough to guarantee that `resolved_path` is within
29154 // the quest "Files" folder, but check to be safe.
29155
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto mismatch_pair = std::mismatch(
29156 2 resolved_path.begin(), resolved_path.end(),
29157 2 files_path.begin(), files_path.end());
29158 2 bool is_subpath = mismatch_pair.second == files_path.end();
29159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!is_subpath)
29160 {
29161 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {}",
29162 user_path, resolved_path.string(), files_path.string()));
29163 }
29164
29165 // Any extension other than banned ones, including no extension, is allowed.
29166
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (is_file && resolved_path.has_extension())
29167 {
29168
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto ext = resolved_path.extension().string();
29169
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (banned_extensions.find(ext) != banned_extensions.end())
29170 return make_unexpected(fmt::format("Bad path: {} - banned extension", user_path));
29171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29172
29173
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (is_file && !resolved_path.has_filename())
29174 return make_unexpected(fmt::format("Bad path: {} - missing filename", user_path));
29175
29176 // https://stackoverflow.com/a/31976060/2788187
29177
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (is_file)
29178 {
29179 static auto banned_fnames = {
29180 "..", ".", "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6",
29181 "COM7", "COM8", "COM9", "CON", "LPT1", "LPT2", "LPT3", "LPT4",
29182 "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN",
29183 };
29184
29185
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto stem = resolved_path.stem().string();
29186
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto fname = resolved_path.filename().string();
29187
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 bool banned = std::find(std::begin(banned_fnames), std::end(banned_fnames), stem) != std::end(banned_fnames);
29188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 banned |= fname.ends_with(".") || fname.ends_with(" ");
29189
29190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (banned)
29191 return make_unexpected(fmt::format("Bad path: {} - banned filename", user_path));
29192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29193
29194
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return resolved_path.string();
29195 2 }
29196
29197 bool FFScript::get_scriptfile_path(char* buf, const char* path)
29198 {
29199 while((path[0] == '/' || path[0] == '\\') && path[0]) ++path;
29200 if(path[0])
29201 sprintf(buf, "%s%c%s", qst_files_path, PATH_SLASH, path);
29202 else sprintf(buf, "%s", qst_files_path);
29203 return true;
29204 }
29205
29206 280 void check_file_error(int32_t ref)
29207 {
29208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(user_file* f = checkFile(ref, true, true))
29209 {
29210 280 int32_t err = ferror(f->file);
29211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(err != 0)
29212 {
29213 Z_scripterrlog("File with UID '%d' encountered an error.\n", ref);
29214 Z_scripterrlog("File error: %s\n", strerror(err));
29215 }
29216 280 }
29217 280 }
29218
29219 2 void FFScript::do_fopen(const bool v, const char* f_mode)
29220 {
29221 2 int32_t arrayptr = SH::get_arg(sarg1, v);
29222 2 string user_path;
29223
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ArrayH::getString(arrayptr, user_path, 512);
29224
29225 2 ri->d[rEXP1] = 0L; //Presume failure; update to 10000L on success
29226 2 ri->d[rEXP2] = 0;
29227
29228 2 std::string resolved_path;
29229
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 if (auto r = parse_user_path(user_path, true); !r)
29230 {
29231 scripting_log_error_with_context("Error: {}", r.error());
29232 return;
29233
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 } else resolved_path = r.value();
29234
29235
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 user_file* f = checkFile(ri->fileref, false, true);
29236
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!f) //auto-allocate
29237 {
29238
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ri->fileref = user_files.get_free();
29239
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f = checkFile(ri->fileref, false, true);
29240 2 }
29241 2 ri->d[rEXP2] = ri->fileref; //Returns to the variable!
29242
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(f)
29243 {
29244
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->close(); //Close the old FILE* before overwriting it!
29245 2 bool create = false;
29246
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 for(int32_t q = 0; f_mode[q]; ++q)
29247 {
29248
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
4 if(f_mode[q] == 'w' || f_mode[q] == 'a')
29249 {
29250 1 create = true;
29251 1 break;
29252 }
29253 3 }
29254
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 if(!create || make_dirs_for_file(resolved_path))
29255 {
29256
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->file = fopen(resolved_path.c_str(), f_mode);
29257
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fflush(f->file);
29258
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 zc_chmod(resolved_path.c_str(), SCRIPT_FILE_MODE);
29259
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->setPath(resolved_path.c_str());
29260 //r+; read-write, will not create if does not exist, will not delete content if does exist.
29261 //w+; read-write, will create if does not exist, will delete all content if does exist.
29262
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(f->file)
29263 {
29264 1 ri->d[rEXP1] = 10000L; //Success
29265 1 return;
29266 }
29267 1 }
29268 else
29269 {
29270 Z_scripterrlog("Script failed to create directories for file path '%s'.\n", resolved_path.c_str());
29271 ri->d[rEXP2] = 0;
29272 return;
29273 }
29274 1 }
29275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29276
29277 void FFScript::do_fremove()
29278 {
29279 if(user_file* f = checkFile(ri->fileref, true))
29280 {
29281 zprint2("Removing file %d\n", ri->fileref);
29282 ri->d[rEXP1] = f->do_remove() ? 0L : 10000L;
29283 }
29284 else ri->d[rEXP1] = 0L;
29285 }
29286
29287 void FFScript::do_fclose()
29288 {
29289 if(user_file* f = checkFile(ri->fileref, false, true))
29290 {
29291 f->close();
29292 }
29293 //No else. If invalid, no error is thrown.
29294 }
29295
29296 void FFScript::do_allocate_file()
29297 {
29298 //Get a file and return it
29299 ri->fileref = user_files.get_free();
29300 ri->d[rEXP2] = ri->fileref; //Return to ptr
29301 ri->d[rEXP1] = (ri->d[rEXP2] == 0 ? 0L : 10000L);
29302 }
29303
29304 1 void FFScript::do_deallocate_file()
29305 {
29306 1 user_file* f = checkFile(ri->fileref, false, true);
29307
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(f) free_script_object(f->id);
29308 1 }
29309
29310 void FFScript::do_file_isallocated() //Returns true if file is allocated
29311 {
29312 user_file* f = checkFile(ri->fileref, false, true);
29313 ri->d[rEXP1] = (f) ? 10000L : 0L;
29314 }
29315
29316 void FFScript::do_file_isvalid() //Returns true if file is allocated and has an open FILE*
29317 {
29318 user_file* f = checkFile(ri->fileref, true, true);
29319 ri->d[rEXP1] = (f) ? 10000L : 0L;
29320 }
29321
29322 1 void FFScript::do_fflush()
29323 {
29324 1 ri->d[rEXP1] = 0L;
29325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(user_file* f = checkFile(ri->fileref, true))
29326 {
29327
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!fflush(f->file))
29328 1 ri->d[rEXP1] = 10000L;
29329 1 check_file_error(ri->fileref);
29330 1 }
29331 1 }
29332
29333 void FFScript::do_file_readchars()
29334 {
29335 if(user_file* f = checkFile(ri->fileref, true))
29336 {
29337 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29338 int32_t count = get_register(sarg2) / 10000;
29339 if(count == 0) return;
29340 int32_t arrayptr = get_register(sarg1);
29341 ArrayManager am(arrayptr);
29342 int32_t sz = am.size();
29343 if(sz <= 0)
29344 return;
29345 if(pos >= sz)
29346 {
29347 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadChars()", arrayptr);
29348 return;
29349 }
29350 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29351 int32_t limit = pos+count;
29352 char c;
29353 word q;
29354 ri->d[rEXP1] = 0;
29355 for(q = pos; q < limit; ++q)
29356 {
29357 c = fgetc(f->file);
29358 if(feof(f->file) || ferror(f->file))
29359 break;
29360 if(c <= 0)
29361 break;
29362 am.set(q,c * 10000L);
29363 ++ri->d[rEXP1]; //Don't count nullchar towards length
29364 }
29365 if(q >= limit)
29366 {
29367 --q;
29368 --ri->d[rEXP1];
29369 ungetc(am.get(q), f->file); //Put the character back before overwriting it
29370 }
29371 am.set(q,0); //Force null-termination
29372 ri->d[rEXP1] *= 10000L;
29373 check_file_error(ri->fileref);
29374 return;
29375 }
29376 ri->d[rEXP1] = 0L;
29377 }
29378 void FFScript::do_file_readbytes()
29379 {
29380 if(user_file* f = checkFile(ri->fileref, true))
29381 {
29382 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29383 int32_t count = get_register(sarg2) / 10000;
29384 if(count == 0) return;
29385 int32_t arrayptr = get_register(sarg1);
29386 ArrayManager am(arrayptr);
29387 int32_t sz = am.size();
29388 if(sz <= 0)
29389 return;
29390 if(pos >= sz)
29391 {
29392 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadBytes()", arrayptr);
29393 return;
29394 }
29395 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29396 std::vector<uint8_t> data(count);
29397 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 1, count, f->file);
29398 for(int32_t q = 0; q < count; ++q)
29399 {
29400 am.set(q+pos, 10000L * data[q]);
29401 }
29402 check_file_error(ri->fileref);
29403 return;
29404 }
29405 ri->d[rEXP1] = 0L;
29406 }
29407 void FFScript::do_file_readstring()
29408 {
29409 if(user_file* f = checkFile(ri->fileref, true))
29410 {
29411 int32_t arrayptr = get_register(sarg1);
29412 ArrayManager am(arrayptr);
29413 int32_t sz = am.size();
29414 if(sz <= 0)
29415 return;
29416 int32_t limit = sz;
29417 int32_t c;
29418 word q;
29419 ri->d[rEXP1] = 0;
29420 for(q = 0; q < limit; ++q)
29421 {
29422 c = fgetc(f->file);
29423 if(feof(f->file) || ferror(f->file))
29424 break;
29425 if(c <= 0)
29426 break;
29427 am.set(q,c * 10000L);
29428 ++ri->d[rEXP1]; //Don't count nullchar towards length
29429 if(c == '\n')
29430 {
29431 ++q;
29432 break;
29433 }
29434 }
29435 if(q >= limit)
29436 {
29437 --q;
29438 --ri->d[rEXP1];
29439 ungetc(am.get(q), f->file); //Put the character back before overwriting it
29440 }
29441 am.set(q,0); //Force null-termination
29442 ri->d[rEXP1] *= 10000L;
29443 check_file_error(ri->fileref);
29444 return;
29445 }
29446 ri->d[rEXP1] = 0L;
29447 }
29448 void FFScript::do_file_readints()
29449 {
29450 if(user_file* f = checkFile(ri->fileref, true))
29451 {
29452 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29453 int32_t count = get_register(sarg2) / 10000;
29454 if(count == 0) return;
29455 int32_t arrayptr = get_register(sarg1);
29456 ArrayManager am(arrayptr);
29457 int32_t sz = am.size();
29458 if(sz <= 0)
29459 return;
29460 if(pos >= sz)
29461 {
29462 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadInts()", arrayptr);
29463 return;
29464 }
29465 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29466
29467 std::vector<int32_t> data(count);
29468 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 4, count, f->file);
29469 for(int32_t q = 0; q < count; ++q)
29470 {
29471 am.set(q+pos,data[q]);
29472 }
29473 check_file_error(ri->fileref);
29474 return;
29475 }
29476 ri->d[rEXP1] = 0L;
29477 }
29478 void FFScript::do_file_writechars()
29479 {
29480 if(user_file* f = checkFile(ri->fileref, true))
29481 {
29482 int32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29483 int32_t count = get_register(sarg2) / 10000;
29484 if(count == 0) return;
29485 if(count == -1 || count > (MAX_ZC_ARRAY_SIZE-pos)) count = MAX_ZC_ARRAY_SIZE-pos;
29486 int32_t arrayptr = get_register(sarg1);
29487 string output;
29488 ArrayH::getString(arrayptr, output, count, pos);
29489 uint32_t q = 0;
29490 for(; q < output.length(); ++q)
29491 {
29492 if(fputc(output[q], f->file)<0)
29493 break;
29494 }
29495 ri->d[rEXP1] = q * 10000L;
29496 check_file_error(ri->fileref);
29497 return;
29498 }
29499 ri->d[rEXP1] = 0L;
29500 }
29501
29502 void FFScript::do_file_writebytes()
29503 {
29504 if(user_file* f = checkFile(ri->fileref, true))
29505 {
29506 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29507 int32_t arg = get_register(sarg2) / 10000;
29508 if(arg == 0) return;
29509 uint32_t count = ((arg<0 || unsigned(arg) >(MAX_ZC_ARRAY_SIZE - pos)) ? MAX_ZC_ARRAY_SIZE - pos : unsigned(arg));
29510 int32_t arrayptr = get_register(sarg1);
29511 string output;
29512 ArrayManager am(arrayptr);
29513 if(am.invalid()) return;
29514 int32_t sz = am.size();
29515 if(sz <= 0)
29516 return;
29517 if(pos >= sz)
29518 {
29519 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteBytes()", arrayptr);
29520 return;
29521 }
29522 if (count > sz-pos) count = sz-pos;
29523 std::vector<uint8_t> data(count);
29524 for(uint32_t q = 0; q < count; ++q)
29525 {
29526 data[q] = am.get(q+pos) / 10000;
29527 }
29528 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 1, count, f->file);
29529 check_file_error(ri->fileref);
29530 return;
29531 }
29532 ri->d[rEXP1] = 0L;
29533 }
29534 279 void FFScript::do_file_writestring()
29535 {
29536
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 if(user_file* f = checkFile(ri->fileref, true))
29537 {
29538 279 int32_t arrayptr = get_register(sarg1);
29539 279 string output;
29540
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 ArrayH::getString(arrayptr, output, ZSCRIPT_MAX_STRING_CHARS);
29541 279 uint32_t q = 0;
29542
2/2
✓ Branch 0 taken 12719 times.
✓ Branch 1 taken 279 times.
12998 for(; q < output.length(); ++q)
29543 {
29544
3/6
✓ Branch 0 taken 12719 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12719 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12719 times.
✗ Branch 5 not taken.
12719 if(fputc(output[q], f->file)<0)
29545 break;
29546 12719 }
29547 279 ri->d[rEXP1] = q * 10000L;
29548
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 check_file_error(ri->fileref);
29549 return;
29550 279 }
29551 ri->d[rEXP1] = 0L;
29552 279 }
29553 void FFScript::do_file_writeints()
29554 {
29555 if(user_file* f = checkFile(ri->fileref, true))
29556 {
29557 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29558 int32_t count = get_register(sarg2) / 10000;
29559 if(count == 0) return;
29560 int32_t arrayptr = get_register(sarg1);
29561 ArrayManager am(arrayptr);
29562 if(am.invalid()) return;
29563 int32_t sz = am.size();
29564 if(sz <= 0)
29565 return;
29566 if(pos >= sz)
29567 {
29568 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteInts()", arrayptr);
29569 return;
29570 }
29571
29572 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29573 std::vector<int32_t> data(count);
29574 for(int32_t q = 0; q < count; ++q)
29575 {
29576 data[q] = am.get(q+pos);
29577 }
29578 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 4, count, f->file);
29579 check_file_error(ri->fileref);
29580 return;
29581 }
29582 ri->d[rEXP1] = 0L;
29583 }
29584
29585 void FFScript::do_file_getchar()
29586 {
29587 if(user_file* f = checkFile(ri->fileref, true))
29588 {
29589 ri->d[rEXP1] = fgetc(f->file) * 10000L;
29590 check_file_error(ri->fileref);
29591 return;
29592 }
29593 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29594 }
29595 void FFScript::do_file_putchar()
29596 {
29597 if(user_file* f = checkFile(ri->fileref, true))
29598 {
29599 int32_t c = get_register(sarg1) / 10000;
29600 if(char(c) != c)
29601 {
29602 Z_scripterrlog("Invalid character val %d passed to PutChar(); value will overflow.", c);
29603 c = char(c);
29604 }
29605 ri->d[rEXP1] = fputc(c, f->file) * 10000L;
29606 check_file_error(ri->fileref);
29607 return;
29608 }
29609 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29610 }
29611 void FFScript::do_file_ungetchar()
29612 {
29613 if(user_file* f = checkFile(ri->fileref, true))
29614 {
29615 int32_t c = get_register(sarg1) / 10000;
29616 if(char(c) != c)
29617 {
29618 Z_scripterrlog("Invalid character val %d passed to UngetChar(); value will overflow.", c);
29619 c = char(c);
29620 }
29621 ri->d[rEXP1] = ungetc(c,f->file) * 10000L;
29622 check_file_error(ri->fileref);
29623 return;
29624 }
29625 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29626 }
29627
29628 void FFScript::do_file_seek()
29629 {
29630 if(user_file* f = checkFile(ri->fileref, true))
29631 {
29632 int32_t pos = get_register(sarg1); //NOT /10000 -V
29633 int32_t origin = get_register(sarg2) ? SEEK_CUR : SEEK_SET;
29634 ri->d[rEXP1] = fseek(f->file, pos, origin) ? 0L : 10000L;
29635 check_file_error(ri->fileref);
29636 return;
29637 }
29638 ri->d[rEXP1] = 0;
29639 }
29640 void FFScript::do_file_rewind()
29641 {
29642 if(user_file* f = checkFile(ri->fileref, true))
29643 {
29644 //fseek(f->file, 0L, SEEK_END);
29645 rewind(f->file);
29646 check_file_error(ri->fileref);
29647 }
29648 }
29649 void FFScript::do_file_clearerr()
29650 {
29651 if(user_file* f = checkFile(ri->fileref, true))
29652 {
29653 clearerr(f->file);
29654 }
29655 }
29656
29657 void FFScript::do_file_geterr()
29658 {
29659 if(user_file* f = checkFile(ri->fileref, true))
29660 {
29661 int32_t err = ferror(f->file);
29662 int32_t arrayptr = get_register(sarg1);
29663 if(err)
29664 {
29665 string error = strerror(err);
29666 ArrayH::setArray(arrayptr, error);
29667 }
29668 else
29669 {
29670 ArrayH::setArray(arrayptr, "\0");
29671 }
29672 }
29673 }
29674 ///----------------------------------------------------------------------------------------------------
29675 //Directory
29676
29677 void FFScript::do_directory_get()
29678 {
29679 if(user_dir* dr = checkDir(ri->directoryref, true))
29680 {
29681 int32_t indx = get_register(sarg1) / 10000L;
29682 int32_t arrayptr = get_register(sarg2);
29683 char buf[2048] = {0};
29684 set_register(sarg1, dr->get(indx, buf) ? 10000L : 0L);
29685 if(ArrayH::setArray(arrayptr, string(buf)) == SH::_Overflow)
29686 scripting_log_error_with_context("Array is not large enough");
29687 }
29688 else set_register(sarg1, 0L);
29689 }
29690
29691 void FFScript::do_directory_reload()
29692 {
29693 if(user_dir* dr = checkDir(ri->directoryref, true))
29694 {
29695 dr->refresh();
29696 }
29697 }
29698
29699 void FFScript::do_directory_free()
29700 {
29701 if(user_dir* dr = checkDir(ri->directoryref, true))
29702 {
29703 free_script_object(dr->id);
29704 }
29705 }
29706
29707 ///----------------------------------------------------------------------------------------------------
29708
29709 void FFScript::set_sarg1(int32_t v)
29710 {
29711 set_register(sarg1, v);
29712 }
29713
29714 5 void FFScript::do_isvalidbitmap()
29715 {
29716 5 int32_t id = get_register(sarg1);
29717
29718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (id >= 0)
29719 {
29720 5 auto bmp = user_bitmaps.check(id, true);
29721
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5 if (bmp && bmp->u_bmp)
29722 {
29723 set_register(sarg1, 10000);
29724 return;
29725 }
29726 5 }
29727
29728 5 set_register(sarg1, 0);
29729 5 }
29730 43 void FFScript::do_isallocatedbitmap()
29731 {
29732 43 int32_t id = get_register(sarg1);
29733
29734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (id >= 0)
29735 {
29736 43 auto bmp = user_bitmaps.check(id, true);
29737
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
43 if (bmp)
29738 {
29739 42 set_register(sarg1, 10000);
29740 42 return;
29741 }
29742 1 }
29743
29744 1 set_register(sarg1, 0);
29745 43 }
29746
29747 422 void FFScript::user_bitmaps_init()
29748 {
29749 422 user_bitmaps.clear();
29750 422 }
29751
29752 3858 int32_t FFScript::do_create_bitmap()
29753 {
29754 3858 int32_t w = (ri->d[rINDEX2] / 10000);
29755 3858 int32_t h = (ri->d[rINDEX]/10000);
29756
1/2
✓ Branch 0 taken 3858 times.
✗ Branch 1 not taken.
3858 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
29757 {
29758 std::swap(w, h);
29759 }
29760
29761 3858 return create_user_bitmap_ex(h,w);
29762 }
29763
29764 3858 uint32_t FFScript::create_user_bitmap_ex(int32_t w, int32_t h)
29765 {
29766 3858 auto bmp = user_bitmaps.create();
29767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3858 times.
3858 if (!bmp)
29768 return 0;
29769
29770 3858 bmp->width = w;
29771 3858 bmp->height = h;
29772 3858 bmp->u_bmp = create_bitmap_ex(8,w,h);
29773 3858 clear_bitmap(bmp->u_bmp);
29774 3858 return bmp->id;
29775 3858 }
29776
29777 1800 bool FFScript::doesResolveToScreenBitmap(int32_t bitmap_id)
29778 {
29779
2/2
✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 360 times.
1800 if (bitmap_id == rtSCREEN)
29780 360 return true;
29781
29782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (bitmap_id == -2)
29783 {
29784 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
29785 if (curr_rt >= 0 && curr_rt < 7)
29786 return false;
29787
29788 return true;
29789 }
29790
29791 1440 return false;
29792 1800 }
29793
29794 1800 bool FFScript::doesResolveToDeprecatedSystemBitmap(int32_t bitmap_id)
29795 {
29796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 switch (bitmap_id)
29797 {
29798 case rtBMP0:
29799 case rtBMP1:
29800 case rtBMP2:
29801 case rtBMP3:
29802 case rtBMP4:
29803 case rtBMP5:
29804 case rtBMP6:
29805 {
29806 return true;
29807 }
29808 }
29809
29810
1/2
✓ Branch 0 taken 1800 times.
✗ Branch 1 not taken.
1800 if (bitmap_id == -2)
29811 {
29812 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
29813 if (curr_rt >= 0 && curr_rt < 7)
29814 return true;
29815 }
29816
29817 1800 return false;
29818 1800 }
29819
29820 53694974 BITMAP* FFScript::GetScriptBitmap(int32_t id, BITMAP* screen_bmp, bool skipError)
29821 {
29822
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 53694494 times.
✓ Branch 2 taken 480 times.
53694974 switch (id - 10)
29823 {
29824 case rtSCREEN:
29825 480 return screen_bmp;
29826
29827 case rtBMP0:
29828 case rtBMP1:
29829 case rtBMP2:
29830 case rtBMP3:
29831 case rtBMP4:
29832 case rtBMP5:
29833 case rtBMP6: //old system bitmaps (render targets)
29834 {
29835 return zscriptDrawingRenderTarget->GetBitmapPtr(id - 10);
29836 }
29837 }
29838
29839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53694494 times.
53694494 if (auto bitmap = checkBitmap(id, true, skipError))
29840 53694494 return bitmap->u_bmp;
29841
29842 return nullptr;
29843 53694974 }
29844
29845 225 uint32_t FFScript::get_free_bitmap(bool skipError)
29846 {
29847 225 auto bmp = user_bitmaps.create(skipError);
29848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 if (!bmp)
29849 return 0;
29850 225 return bmp->id;
29851 225 }
29852
29853 3512 void FFScript::do_deallocate_bitmap()
29854 {
29855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3512 times.
3512 if (ZScriptVersion::gc())
29856 return;
29857
29858
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if(isSystemBitref(ri->bitmapref))
29859 {
29860 return; //Don't attempt to deallocate system bitmaps!
29861 }
29862
29863 // Bitmaps are not deallocated right away, but deferred until the next call to scb.update()
29864
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if (auto b = checkBitmap(ri->bitmapref, false, true))
29865 3512 b->free_obj();
29866 3512 }
29867
29868 3658 bool FFScript::isSystemBitref(int32_t ref)
29869 {
29870
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 switch(ref-10)
29871 {
29872 case rtSCREEN:
29873 case rtBMP0:
29874 case rtBMP1:
29875 case rtBMP2:
29876 case rtBMP3:
29877 case rtBMP4:
29878 case rtBMP5:
29879 case rtBMP6:
29880 return true;
29881 }
29882 3658 return false;
29883 3658 }
29884
29885 ///----------------------------------------------------------------------------------------------------
29886
29887 1661 int32_t FFScript::GetQuestVersion()
29888 {
29889 1661 return QHeader.zelda_version;
29890 }
29891 729 int32_t FFScript::GetQuestBuild()
29892 {
29893 729 return QHeader.build;
29894 }
29895 int32_t FFScript::GetQuestSectionVersion(int32_t section)
29896 {
29897 return QHeader.zelda_version;
29898 }
29899
29900 19 int32_t FFScript::GetDefaultWeaponSprite(int32_t wpn_id)
29901 {
29902
2/63
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 10 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
19 switch (wpn_id)
29903 {
29904 case wNone:
29905 return 0;
29906
29907 case wSword: return 0;
29908 case wBeam: return 1;
29909 case wBrang: return 4;
29910 case wBomb: return 9;
29911 case wSBomb: return 75;
29912 case wLitBomb: return 7;
29913 case wLitSBomb: return 8;
29914 case wArrow: return 10;
29915 case wRefArrow: return 10;
29916 case wFire: return 12;
29917 case wRefFire: return 12;
29918 case wRefFire2: return 12;
29919 case wWhistle: return 45; //blank, unused misc sprite
29920 case wBait: return 14;
29921 case wWand: return 15;
29922 case wMagic: return 16;
29923 case wCatching: return 45; //blank, unused misc sprite
29924 case wWind: return 13;
29925 case wRefMagic: return 16;
29926 case wRefFireball: return 17;
29927 case wRefRock: return 18;
29928 case wHammer: return 25;
29929 case wHookshot: return 26;
29930 case wHSHandle: return 28;
29931 case wHSChain: return 27;
29932 case wSSparkle: return 29;
29933 case wFSparkle: return 32;
29934 case wSmack: return 33;
29935 case wPhantom: return -1;
29936 case wCByrna: return 87;
29937 case wRefBeam: return 1;
29938 case wStomp: return 45; //blank, unused misc sprite
29939 case lwMax: return 45; //blank, unused misc sprite
29940 case wScript1: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 246; else return 0; }
29941 case wScript2: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 247; else return 0; }
29942 case wScript3: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 248; else return 0; }
29943 case wScript4: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 249; else return 0; }
29944 case wScript5: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 250; else return 0; }
29945 case wScript6: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 251; else return 0; }
29946 case wScript7: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 252; else return 0; }
29947 case wScript8: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 253; else return 0; }
29948 case wScript9: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 254; else return 0; }
29949 case wScript10: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 255; else return 0; }
29950
29951 case wIce: return 83;
29952 //Cannot use any of these weapons yet.
29953 //return -1;
29954
29955 case wEnemyWeapons:
29956 9 case ewFireball: return 17;
29957
29958 case ewArrow: return 19;
29959 case ewBrang: return 4;
29960 10 case ewSword: return 20;
29961 case ewRock: return 18;
29962 case ewMagic: return 21;
29963 case ewBomb: return 78;
29964 case ewSBomb: return 79;
29965 case ewLitBomb: return 76;
29966 case ewLitSBomb: return 77;
29967 case ewFireTrail: return 80;
29968 case ewFlame: return 35;
29969 case ewWind: return 36;
29970 case ewFlame2: return 81;
29971 case ewFlame2Trail: return 82;
29972 case ewIce: return 83;
29973 case ewFireball2: return 17; //fireball (rising)
29974
29975
29976 default: return -1; //No assign.
29977
29978 }
29979 19 }
29980
29981 19 int32_t FFScript::GetDefaultWeaponSFX(int32_t wpn_id)
29982 {
29983
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
19 switch (wpn_id)
29984 {
29985 case ewFireTrail:
29986 case ewFlame:
29987 case ewFlame2Trail:
29988 case ewFlame2:
29989 return WAV_FIRE; break;
29990 case ewWind:
29991 case ewMagic:
29992 return WAV_WAND; break;
29993 case ewIce:
29994 return WAV_ZN1ICE; break;
29995 case ewRock:
29996 return WAV_ZN1ROCK; break;
29997 case ewFireball2:
29998 case ewFireball:
29999 9 return WAV_ZN1FIREBALL; break;
30000 }
30001 10 return -1; //no assign
30002 19 }
30003
30004 //bitmap->GetPixel()
30005
30006
30007 int32_t FFScript::do_getpixel()
30008 {
30009 int32_t xoffset = 0, yoffset = 0;
30010 int32_t xoff = 0; int32_t yoff = 0;
30011 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0)
30012 || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
30013
30014 BITMAP *bitty = FFCore.GetScriptBitmap(ri->bitmapref, screen);
30015 if(!bitty)
30016 {
30017 bitty = scrollbuf;
30018 }
30019 // draw to screen with subscreen offset
30020 if(!brokenOffset && ri->bitmapref == rtSCREEN + 10 )
30021 {
30022 xoffset = xoff;
30023 yoffset = 56; //should this be -56?
30024 }
30025 else
30026 {
30027 xoffset = 0;
30028 yoffset = 0;
30029 }
30030
30031 int32_t yv = ri->d[rINDEX2]/10000 + yoffset;
30032 int32_t ret = getpixel(bitty, ri->d[rINDEX]/10000, yv); //This is a palette index value.
30033 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
30034 ret *= 10000;
30035 return ret;
30036 }
30037
30038 void FFScript::do_bmpcollision()
30039 {
30040 int32_t bmpref = SH::read_stack(ri->sp + 5);
30041 int32_t maskbmpref = SH::read_stack(ri->sp + 4);
30042 int32_t x = SH::read_stack(ri->sp + 3) / 10000;
30043 int32_t y = SH::read_stack(ri->sp + 2) / 10000;
30044 int32_t checkCol = SH::read_stack(ri->sp + 1) / 10000;
30045 int32_t maskCol = SH::read_stack(ri->sp + 0) / 10000;
30046 BITMAP *checkbit = FFCore.GetScriptBitmap(bmpref, screen, true);
30047 BITMAP *maskbit = FFCore.GetScriptBitmap(maskbmpref, screen, true);
30048 if(!(checkbit && maskbit))
30049 {
30050 set_register(sarg1, -10000);
30051 char buf1[16];
30052 char buf2[16];
30053 zc_itoa(bmpref, buf1);
30054 zc_itoa(maskbmpref, buf2);
30055 Z_scripterrlog("Invalid bitmap%s passed to 'bitmap->CountColor()': %s%s%s\n",
30056 (checkbit || maskbit) ? "" : "s", checkbit ? "" : buf1,
30057 (checkbit || maskbit) ? "" : ", ", maskbit ? "" : buf2);
30058 return;
30059 }
30060 int32_t ret = countColor(checkbit, maskbit, x, y, checkCol, maskCol);
30061 set_register(sarg1, ret*10000);
30062 }
30063
30064
30065 6567172 int32_t FFScript::loadMapData()
30066 {
30067 6567172 int32_t map = (ri->d[rINDEX] / 10000);
30068 6567172 int32_t screen = (ri->d[rINDEX2]/10000);
30069
1/2
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
6567172 int32_t indx = (zc_max((map)-1,0) * MAPSCRS + screen);
30070
2/4
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567172 times.
6567172 if ( map < 1 || map > map_count )
30071 {
30072 Z_scripterrlog("Invalid Map ID passed to Game->LoadMapData: %d\n", map);
30073 ri->mapsref = MAX_SIGNED_32;
30074 }
30075
2/4
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567172 times.
6567172 else if ( screen < 0 || screen > 129 ) //0x00 to 0x81 -Z
30076 {
30077 Z_scripterrlog("Invalid Screen Index passed to Game->LoadMapData: %d\n", screen);
30078 ri->mapsref = MAX_SIGNED_32;
30079 }
30080 6567172 else ri->mapsref = indx;
30081 6567172 return ri->mapsref;
30082 }
30083
30084 // Called when leaving a screen; deallocate arrays created by FFCs that aren't carried over
30085 13690324 void FFScript::deallocateArray(int32_t ptrval)
30086 {
30087
1/2
✓ Branch 0 taken 13690324 times.
✗ Branch 1 not taken.
13690324 CHECK(!ZScriptVersion::gc_arrays());
30088
30089
1/2
✓ Branch 0 taken 13690324 times.
✗ Branch 1 not taken.
13690324 if(ptrval == 0)
30090 return;
30091
2/4
✓ Branch 0 taken 13690324 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13690324 times.
13690324 if(ptrval==0 || ptrval >= NUM_ZSCRIPT_ARRAYS)
30092 scripting_log_error_with_context("Script tried to deallocate memory at invalid address {}", ptrval);
30093
1/2
✓ Branch 0 taken 13690324 times.
✗ Branch 1 not taken.
13690324 else if(ptrval<0)
30094 scripting_log_error_with_context("Script tried to deallocate memory at object-based address {}", ptrval);
30095 else
30096 {
30097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690324 times.
13690324 if(arrayOwner[ptrval].specOwned) return; //ignore this deallocation
30098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690324 times.
13690324 if(arrayOwner[ptrval].specCleared) return;
30099 13690324 arrayOwner[ptrval].clear();
30100
30101
1/2
✓ Branch 0 taken 13690324 times.
✗ Branch 1 not taken.
13690324 if(!localRAM[ptrval].Valid())
30102 scripting_log_error_with_context("Script tried to deallocate memory that was not allocated at address {}", ptrval);
30103 else
30104 {
30105
2/2
✓ Branch 0 taken 13690321 times.
✓ Branch 1 taken 3 times.
13690324 if (localRAM[ptrval].HoldsObjects())
30106 {
30107 3 auto&& aptr = localRAM[ptrval];
30108
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 for (int i = 0; i < aptr.Size(); i++)
30109 {
30110 2 int id = aptr[i];
30111 2 script_object_ref_dec(id);
30112 2 }
30113 3 }
30114 13690324 localRAM[ptrval].Clear();
30115 }
30116 }
30117 13690324 }
30118
30119 2617631 int32_t FFScript::get_screen_d(int32_t index1, int32_t index2)
30120 {
30121
3/4
✓ Branch 0 taken 2617631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2617625 times.
2617631 if(index2 < 0 || index2 > 7)
30122 {
30123 6 scripting_log_error_with_context("You were trying to reference an out-of-bounds array index for a screen's D[] array ({}); valid indices are from 0 to 7.", index1);
30124 6 return 0;
30125 }
30126
2/4
✓ Branch 0 taken 2617625 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2617625 times.
2617625 if (index1 < 0 || index1 >= game->screen_d.size())
30127 {
30128 scripting_log_error_with_context("You were trying to reference an out-of-bounds screen for a D[] array ({}); valid indices are from 0 to %u.", index1, game->screen_d.size() - 1);
30129 return 0;
30130 }
30131
30132 2617625 return game->screen_d[index1][index2];
30133 2617631 }
30134
30135 54370 void FFScript::set_screen_d(int32_t index1, int32_t index2, int32_t val)
30136 {
30137
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if(index2 < 0 || index2 > 7)
30138 {
30139 scripting_log_error_with_context("You were trying to reference an out-of-bounds array index for a screen's D[] array ({}); valid indices are from 0 to 7.", index1);
30140 return;
30141 }
30142
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if (index1 < 0 || index1 >= game->screen_d.size())
30143 {
30144 scripting_log_error_with_context("You were trying to reference an out-of-bounds screen for a D[] array ({}); valid indices are from 0 to %u.", index1, game->screen_d.size() - 1);
30145 return;
30146 }
30147
30148 54370 game->screen_d[index1][index2] = val;
30149 54370 }
30150
30151 void FFScript::do_zapout()
30152 {
30153 zapout();
30154 }
30155
30156 void FFScript::do_zapin(){ zapin(); }
30157
30158 void FFScript::do_openscreen() { openscreen(); }
30159 void FFScript::do_closescreen() { closescreen(); }
30160 void FFScript::do_openscreenshape()
30161 {
30162 int32_t shape = get_register(sarg1) / 10000;
30163 if(shape < 0 || shape >= bosMAX)
30164 {
30165 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->OpeningWipe(int32_t)", 0, bosMAX-1);
30166 shape = bosCIRCLE;
30167 }
30168 openscreen(shape);
30169 }
30170 void FFScript::do_closescreenshape()
30171 {
30172 int32_t shape = get_register(sarg1) / 10000;
30173 if(shape < 0 || shape >= bosMAX)
30174 {
30175 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->ClosingWipe(int32_t)", 0, bosMAX-1);
30176 shape = bosCIRCLE;
30177 }
30178 closescreen(shape);
30179 }
30180 void FFScript::do_wavyin() { wavyin(); }
30181 void FFScript::do_wavyout() { wavyout(false); }
30182
30183
30184 void FFScript::do_triggersecret(const bool v)
30185 {
30186 int32_t ID = vbound((SH::get_arg(sarg1, v) / 10000), 0, 255);
30187 mapscr *s = hero_scr;
30188 //Convert a flag type to a secret type.
30189 int32_t ft = combo_trigger_flag_to_secret_combo_index(ID);
30190 if (ft != -1)
30191 {
30192 for(int32_t iter=0; iter<2; ++iter)
30193 {
30194 for ( int32_t q = 0; q < 176; q++ )
30195 {
30196 //Placed flags
30197 if ( iter == 1 )
30198 {
30199 if ( s->sflag[q] == ID ) {
30200 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
30201 screen_combo_modify_preroutine(rpos_handle);
30202 s->data[q] = s->secretcombo[ft];
30203 s->cset[q] = s->secretcset[ft];
30204 s->sflag[q] = s->secretflag[ft];
30205 screen_combo_modify_postroutine(rpos_handle);
30206 }
30207 }
30208 //Inherent flags
30209 else
30210 {
30211 if ( combobuf[s->data[q]].flag == ID ) {
30212 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
30213 screen_combo_modify_preroutine(rpos_handle);
30214 s->data[q] = s->secretcombo[ft];
30215 s->cset[q] = s->secretcset[ft];
30216 screen_combo_modify_postroutine(rpos_handle);
30217 }
30218
30219 }
30220 }
30221 }
30222 }
30223
30224 }
30225 //NPCData
30226
30227 //NPCData Getter Macros
30228
30229
30230
30231
30232 //NPCData-> Function
30233 #define GET_NPCDATA_FUNCTION_VAR_INT(member) \
30234 { \
30235 int32_t ID = get_register(sarg2) / 10000; \
30236 if(ID < 1 || ID > (MAXGUYS-1)) \
30237 set_register(sarg1, -10000); \
30238 else \
30239 set_register(sarg1, guysbuf[ID].member * 10000); \
30240 }
30241
30242 #define GET_NPCDATA_FUNCTION_VAR_INDEX(member, indexbound) \
30243 { \
30244 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
30245 int32_t indx = vbound((ri->d[rINDEX2] / 10000), 0, indexbound); \
30246 if(ID < 1 || ID > (MAXGUYS-1)) \
30247 set_register(sarg1, -10000); \
30248 else \
30249 set_register(sarg1, guysbuf[ID].member[indx] * 10000); \
30250 }
30251
30252 #define GET_NPCDATA_FUNCTION_VAR_FLAG(member) \
30253 { \
30254 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
30255 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30256 if(ID < 1 || ID > (MAXGUYS-1)) \
30257 set_register(sarg1, -10000); \
30258 else \
30259 set_register(sarg1, (guysbuf[ID].member&flag) ? 10000 : 0); \
30260 }
30261
30262 uint32_t get_upper_half_uint64(uint64_t value)
30263 {
30264 return value >> 32;
30265 }
30266
30267 uint32_t get_lower_half_uint64(uint64_t value)
30268 {
30269 return value & 0xFFFFFFFF;
30270 }
30271
30272 // Defunct.
30273 void FFScript::getNPCData_flags(){
30274 int32_t ID = get_register(sarg2) / 10000;
30275 if(ID < 1 || ID > (MAXGUYS-1))
30276 set_register(sarg1, -10000);
30277 else
30278 set_register(sarg1, get_upper_half_uint64(guysbuf[ID].flags) * 10000);
30279 }
30280
30281 // Defunct.
30282 void FFScript::getNPCData_flags2(){
30283 int32_t ID = get_register(sarg2) / 10000;
30284 if(ID < 1 || ID > (MAXGUYS-1))
30285 set_register(sarg1, -10000);
30286 else
30287 set_register(sarg1, get_lower_half_uint64(guysbuf[ID].flags) * 10000);
30288 }
30289
30290 void FFScript::getNPCData_tile() { GET_NPCDATA_FUNCTION_VAR_INT(tile); }
30291 void FFScript::getNPCData_width(){ GET_NPCDATA_FUNCTION_VAR_INT(width); }
30292 void FFScript::getNPCData_height(){ GET_NPCDATA_FUNCTION_VAR_INT(height); }
30293 void FFScript::getNPCData_s_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(s_tile); }
30294 void FFScript::getNPCData_s_width(){ GET_NPCDATA_FUNCTION_VAR_INT(s_width); }
30295 void FFScript::getNPCData_s_height(){ GET_NPCDATA_FUNCTION_VAR_INT(s_height); }
30296 void FFScript::getNPCData_e_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(e_tile); }
30297 void FFScript::getNPCData_e_width(){ GET_NPCDATA_FUNCTION_VAR_INT(e_width); }
30298 void FFScript::getNPCData_e_height() { GET_NPCDATA_FUNCTION_VAR_INT(e_height); }
30299 void FFScript::getNPCData_hp(){ GET_NPCDATA_FUNCTION_VAR_INT(hp); }
30300 void FFScript::getNPCData_family(){ GET_NPCDATA_FUNCTION_VAR_INT(family); }
30301 void FFScript::getNPCData_cset(){ GET_NPCDATA_FUNCTION_VAR_INT(cset); }
30302 void FFScript::getNPCData_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(anim); }
30303 void FFScript::getNPCData_e_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(e_anim); }
30304 void FFScript::getNPCData_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(frate); }
30305 void FFScript::getNPCData_e_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(e_frate); }
30306 void FFScript::getNPCData_dp(){ GET_NPCDATA_FUNCTION_VAR_INT(dp); }
30307 void FFScript::getNPCData_wdp(){ GET_NPCDATA_FUNCTION_VAR_INT(wdp); }
30308 void FFScript::getNPCData_weapon(){ GET_NPCDATA_FUNCTION_VAR_INT(weapon); }
30309 void FFScript::getNPCData_rate(){ GET_NPCDATA_FUNCTION_VAR_INT(rate); }
30310 void FFScript::getNPCData_hrate(){ GET_NPCDATA_FUNCTION_VAR_INT(hrate); }
30311 void FFScript::getNPCData_step(){ GET_NPCDATA_FUNCTION_VAR_INT(step); }
30312 void FFScript::getNPCData_homing(){ GET_NPCDATA_FUNCTION_VAR_INT(homing); }
30313 void FFScript::getNPCData_grumble(){ GET_NPCDATA_FUNCTION_VAR_INT(grumble); }
30314 void FFScript::getNPCData_item_set(){ GET_NPCDATA_FUNCTION_VAR_INT(item_set); }
30315 void FFScript::getNPCData_bgsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(bgsfx); }
30316 void FFScript::getNPCData_hitsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(hitsfx); }
30317 void FFScript::getNPCData_deadsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(deadsfx); }
30318 void FFScript::getNPCData_xofs(){ GET_NPCDATA_FUNCTION_VAR_INT(xofs); }
30319 void FFScript::getNPCData_yofs(){ GET_NPCDATA_FUNCTION_VAR_INT(yofs); }
30320 void FFScript::getNPCData_zofs(){ GET_NPCDATA_FUNCTION_VAR_INT(zofs); }
30321 void FFScript::getNPCData_hxofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hxofs); }
30322 void FFScript::getNPCData_hyofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hyofs); }
30323 void FFScript::getNPCData_hxsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hxsz); }
30324 void FFScript::getNPCData_hysz(){ GET_NPCDATA_FUNCTION_VAR_INT(hysz); }
30325 void FFScript::getNPCData_hzsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hzsz); }
30326 void FFScript::getNPCData_txsz(){ GET_NPCDATA_FUNCTION_VAR_INT(txsz); }
30327 void FFScript::getNPCData_tysz(){ GET_NPCDATA_FUNCTION_VAR_INT(tysz); }
30328 void FFScript::getNPCData_wpnsprite(){ GET_NPCDATA_FUNCTION_VAR_INT(wpnsprite); }
30329 void FFScript::getNPCData_firesfx() { GET_NPCDATA_FUNCTION_VAR_INT(firesfx); }
30330
30331
30332 void FFScript::getNPCData_defense(){GET_NPCDATA_FUNCTION_VAR_INDEX(defense,int32_t(edefLAST255))};
30333
30334
30335 void FFScript::getNPCData_SIZEflags(){GET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags);}
30336
30337
30338 void FFScript::getNPCData_misc()
30339 {
30340 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
30341 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
30342 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES ))
30343 set_register(sarg1, -10000);
30344 else set_register(sarg1, guysbuf[ID].attributes[indx] * 10000);
30345 }
30346
30347 //NPCData Setters, two inputs, no return; similar to void GetDMapIntro(int32_t DMap, int32_t buffer[]);
30348
30349 //NPCData Setter Macros
30350
30351 //Variables for spritedata sp->member
30352
30353
30354
30355 //Functions for NPCData->
30356
30357 #define SET_NPCDATA_FUNCTION_VAR_INT(member, bound) \
30358 { \
30359 int32_t ID = get_register(sarg1) / 10000; \
30360 int32_t val = get_register(sarg2) / 10000; \
30361 if(ID < 1 || ID > (MAXGUYS-1)) \
30362 set_register(sarg1, -10000); \
30363 else \
30364 guysbuf[ID].member = vbound(val,0,bound); \
30365 }
30366
30367 #define SET_NPCDATA_FUNCTION_VAR_ENUM(member, bound) \
30368 { \
30369 int32_t ID = get_register(sarg1) / 10000; \
30370 int32_t val = get_register(sarg2) / 10000; \
30371 if(ID < 1 || ID > (MAXGUYS-1)) \
30372 set_register(sarg1, -10000); \
30373 else \
30374 guysbuf[ID].member = (decltype(guysbuf[ID].member))vbound(val,0,bound); \
30375 }
30376
30377
30378 #define SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(member) \
30379 { \
30380 int32_t ID = get_register(sarg1) / 10000; \
30381 int32_t val = get_register(sarg2) / 10000; \
30382 if(ID < 1 || ID > (MAXGUYS-1)) \
30383 set_register(sarg1, -10000); \
30384 else \
30385 guysbuf[ID].member = val; \
30386 }
30387
30388
30389 //SET_NPC_VAR_INDEX(member,value)
30390 #define SET_NPCDATA_FUNCTION_VAR_INDEX(member, val, bound, indexbound) \
30391 { \
30392 int32_t ID = (ri->d[rINDEX]/10000); \
30393 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
30394 if(ID < 1 || ID > (MAXGUYS-1)) \
30395 return; \
30396 else \
30397 guysbuf[ID].member[indx] = vbound(val,0,bound); \
30398 }
30399
30400 //Special case for flags, three inputs one return
30401 #define SET_NPCDATA_FUNCTION_VAR_FLAG(member, val) \
30402 { \
30403 int32_t ID = (ri->d[rINDEX]/10000); \
30404 int32_t flag = (ri->d[rINDEX2]/10000); \
30405 if(ID < 1 || ID > (MAXGUYS-1)) \
30406 return; \
30407 else \
30408 { \
30409 if ( val != 0 ) guysbuf[ID].member|=flag; \
30410 else guysbuf[ID].member|= ~flag; \
30411 }\
30412 }
30413
30414 static uint64_t set_upper_half_uint64(uint64_t num, uint32_t half)
30415 {
30416 uint64_t lower = num & 0x00000000FFFFFFFF;
30417 return lower | ((uint64_t)half << 32);
30418 }
30419
30420 static uint64_t set_lower_half_uint64(uint64_t num, uint32_t half)
30421 {
30422 uint64_t upper = num & 0xFFFFFFFF00000000;
30423 return upper | half;
30424 }
30425
30426 // Defunct.
30427 void FFScript::setNPCData_flags(){
30428 int32_t ID = get_register(sarg1) / 10000;
30429 int32_t val = get_register(sarg2) / 10000;
30430 if(ID < 1 || ID > (MAXGUYS-1))
30431 set_register(sarg1, -10000);
30432 else
30433 {
30434 guysbuf[ID].flags = (guy_flags)set_upper_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
30435 }
30436 }
30437
30438 // Defunct.
30439 void FFScript::setNPCData_flags2(){
30440 int32_t ID = get_register(sarg1) / 10000;
30441 int32_t val = get_register(sarg2) / 10000;
30442 if(ID < 1 || ID > (MAXGUYS-1))
30443 set_register(sarg1, -10000);
30444 else
30445 {
30446 guysbuf[ID].flags = (guy_flags)set_lower_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
30447 }
30448 }
30449 void FFScript::setNPCData_tile() { SET_NPCDATA_FUNCTION_VAR_INT(tile, ZS_WORD); }
30450 void FFScript::setNPCData_width(){SET_NPCDATA_FUNCTION_VAR_INT(width,ZS_BYTE);}
30451 void FFScript::setNPCData_height(){SET_NPCDATA_FUNCTION_VAR_INT(height,ZS_BYTE);}
30452 void FFScript::setNPCData_s_tile(){SET_NPCDATA_FUNCTION_VAR_INT(s_tile,ZS_WORD);}
30453 void FFScript::setNPCData_s_width(){SET_NPCDATA_FUNCTION_VAR_INT(s_width,ZS_BYTE);}
30454 void FFScript::setNPCData_s_height(){SET_NPCDATA_FUNCTION_VAR_INT(s_height,ZS_BYTE);}
30455 void FFScript::setNPCData_e_tile(){SET_NPCDATA_FUNCTION_VAR_INT(e_tile,ZS_WORD);}
30456 void FFScript::setNPCData_e_width(){SET_NPCDATA_FUNCTION_VAR_INT(e_width,ZS_BYTE);}
30457 void FFScript::setNPCData_e_height() { SET_NPCDATA_FUNCTION_VAR_INT(e_height, ZS_BYTE); }
30458 void FFScript::setNPCData_hp(){SET_NPCDATA_FUNCTION_VAR_INT(hp,ZS_SHORT);}
30459 void FFScript::setNPCData_family(){SET_NPCDATA_FUNCTION_VAR_INT(family,ZS_SHORT);}
30460 void FFScript::setNPCData_cset(){SET_NPCDATA_FUNCTION_VAR_INT(cset,ZS_SHORT);}
30461 void FFScript::setNPCData_anim(){SET_NPCDATA_FUNCTION_VAR_INT(anim,ZS_SHORT);}
30462 void FFScript::setNPCData_e_anim(){SET_NPCDATA_FUNCTION_VAR_INT(e_anim,ZS_SHORT);}
30463 void FFScript::setNPCData_frate(){SET_NPCDATA_FUNCTION_VAR_INT(frate,ZS_SHORT);}
30464 void FFScript::setNPCData_e_frate(){SET_NPCDATA_FUNCTION_VAR_INT(e_frate,ZS_SHORT);}
30465 void FFScript::setNPCData_dp(){SET_NPCDATA_FUNCTION_VAR_INT(dp,ZS_SHORT);}
30466 void FFScript::setNPCData_wdp(){SET_NPCDATA_FUNCTION_VAR_INT(wdp,ZS_SHORT);}
30467 void FFScript::setNPCData_weapon(){SET_NPCDATA_FUNCTION_VAR_INT(weapon,ZS_SHORT);}
30468 void FFScript::setNPCData_rate(){SET_NPCDATA_FUNCTION_VAR_INT(rate,ZS_SHORT);}
30469 void FFScript::setNPCData_hrate(){SET_NPCDATA_FUNCTION_VAR_INT(hrate,ZS_SHORT);}
30470 void FFScript::setNPCData_step(){SET_NPCDATA_FUNCTION_VAR_INT(step,ZS_SHORT);}
30471 void FFScript::setNPCData_homing(){SET_NPCDATA_FUNCTION_VAR_INT(homing,ZS_SHORT);}
30472 void FFScript::setNPCData_grumble(){SET_NPCDATA_FUNCTION_VAR_INT(grumble,ZS_SHORT);}
30473 void FFScript::setNPCData_item_set(){SET_NPCDATA_FUNCTION_VAR_INT(item_set,ZS_SHORT);}
30474 void FFScript::setNPCData_bgsfx(){SET_NPCDATA_FUNCTION_VAR_INT(bgsfx,ZS_SHORT);}
30475 void FFScript::setNPCData_hitsfx(){SET_NPCDATA_FUNCTION_VAR_INT(hitsfx,ZS_BYTE);}
30476 void FFScript::setNPCData_deadsfx(){SET_NPCDATA_FUNCTION_VAR_INT(deadsfx,ZS_BYTE);}
30477 void FFScript::setNPCData_xofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(xofs);}
30478 void FFScript::setNPCData_yofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(yofs);}
30479 void FFScript::setNPCData_zofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(zofs);}
30480 void FFScript::setNPCData_hxofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxofs);}
30481 void FFScript::setNPCData_hyofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hyofs);}
30482 void FFScript::setNPCData_hxsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxsz);}
30483 void FFScript::setNPCData_hysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hysz);}
30484 void FFScript::setNPCData_hzsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hzsz);}
30485 void FFScript::setNPCData_txsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(txsz);}
30486 void FFScript::setNPCData_tysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(tysz);}
30487 void FFScript::setNPCData_wpnsprite(){SET_NPCDATA_FUNCTION_VAR_INT(wpnsprite,511);}
30488 void FFScript::setNPCData_firesfx() { SET_NPCDATA_FUNCTION_VAR_INT(firesfx, 255); }
30489
30490 //NPCData Setters, three inputs, no return. works as SetDMapScreenD function
30491
30492
30493
30494
30495
30496
30497
30498 void FFScript::setNPCData_defense(int32_t v){SET_NPCDATA_FUNCTION_VAR_INDEX(defense,v, ZS_INT, int32_t(edefLAST255) );}
30499 void FFScript::setNPCData_SIZEflags(int32_t v){SET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags,v);}
30500 void FFScript::setNPCData_misc(int32_t val)
30501 {
30502 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
30503 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
30504 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES )) return;
30505 guysbuf[ID].attributes[indx] = val;
30506
30507 };
30508
30509 //ComboData
30510
30511 //Macros
30512
30513 //Are these right? newcombo is *combo_class_buf and the others are *combobuf
30514
30515 //Getters for ComboData 'Type' submembers.
30516 #define GET_COMBODATA_TYPE_INT(member) \
30517 { \
30518 int32_t ID = vbound((get_register(sarg2) / 10000),0,MAXCOMBOS);\
30519 set_register(sarg1, combo_class_buf[combobuf[ID].type].member * 10000); \
30520 }
30521
30522 //this may need additional macros.
30523 //for combo_class_buf[ID].member ?
30524 //I'm not sure which it needs to be at present.
30525
30526 #define GET_COMBODATA_TYPE_INDEX(member, bound) \
30527 { \
30528 int32_t ID = int32_t(vbound((ri->d[rINDEX] / 10000),0,MAXCOMBOS));\
30529 int32_t indx = int32_t(vbound((ri->d[rINDEX2] / 10000), 0, bound));\
30530 set_register(sarg1, combo_class_buf[combobuf[ID].type].member[indx] * 10000); \
30531 }
30532
30533 #define GET_COMBODATA_TYPE_FLAG(member) \
30534 { \
30535 int32_t ID = int32_t(vbound(ri->d[rINDEX] / 10000),0,MAXCOMBOS);\
30536 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30537 set_register(sarg1, (combo_class_buf[combobuf[ID].type].member&flag) ? 10000 : 0); \
30538 }
30539
30540
30541
30542 //Getters for ComboData main members.
30543 #define GET_COMBODATA_VAR_INT(member) \
30544 { \
30545 int32_t ID = vbound( (get_register(sarg2) / 10000), 0, MAXCOMBOS);\
30546 set_register(sarg1, combobuf[ID].member * 10000); \
30547 }
30548
30549 #define GET_COMBODATA_VAR_FLAG(member) \
30550 { \
30551 int32_t ID = int32_t( vbound( ( ri->d[rINDEX] / 10000),0,MAXCOMBOS) );\
30552 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30553 set_register(sarg1, (combobuf[ID].member&flag) ? 10000 : 0); \
30554 }
30555
30556
30557
30558 //ComboData Setter Macros
30559
30560 //Setters for ComboData 'type' submembers.
30561 #define SET_COMBODATA_TYPE_INT(member, bound) \
30562 { \
30563 int32_t ID = get_register(sarg1) / 10000; \
30564 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
30565 if(ID < 1 || ID > 511) \
30566 set_register(sarg1, -10000); \
30567 else \
30568 combo_class_buf[combobuf[ID].type].member = val; \
30569 }
30570
30571 #define SET_COMBODATA_TYPE_INDEX(member, val, bound, indexbound) \
30572 { \
30573 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
30574 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
30575 combo_class_buf[combobuf[ID].type].member[indx] = vbound(val,0,bound); \
30576 }
30577
30578 #define SET_COMBODATA_TYPE_FLAG(member, val, bound) \
30579 { \
30580 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
30581 int32_t flag = (ri->d[rINDEX2]/10000); \
30582 combo_class_buf[combobuf[ID].type].member&flag = ((vbound(val,0,bound))!=0); \
30583 \
30584
30585
30586 //Setters for ComboData main members
30587 #define SET_COMBODATA_VAR_INT(member, bound) \
30588 { \
30589 int32_t ID = vbound( (get_register(sarg1) / 10000), 0, MAXCOMBOS); \
30590 int32_t val = vbound((get_register(sarg2) / 10000),0,bound); \
30591 screen_combo_modify_pre(ID); \
30592 combobuf[ID].member = val; \
30593 screen_combo_modify_post(ID); \
30594 }
30595
30596 //Getters
30597
30598 //one input, one return
30599 void FFScript::getComboData_block_enemies(){ GET_COMBODATA_TYPE_INT(block_enemies); } //byte a
30600 void FFScript::getComboData_block_hole(){ GET_COMBODATA_TYPE_INT(block_hole); } //byte b
30601 void FFScript::getComboData_block_trigger(){ GET_COMBODATA_TYPE_INT(block_trigger); } //byte c
30602 void FFScript::getComboData_conveyor_x_speed(){ GET_COMBODATA_TYPE_INT(conveyor_x_speed); } //int16_t e
30603 void FFScript::getComboData_conveyor_y_speed(){ GET_COMBODATA_TYPE_INT(conveyor_y_speed); } //int16_t f
30604 void FFScript::getComboData_create_enemy(){ GET_COMBODATA_TYPE_INT(create_enemy); } //word g
30605 void FFScript::getComboData_create_enemy_when(){ GET_COMBODATA_TYPE_INT(create_enemy_when); } //byte h
30606 void FFScript::getComboData_create_enemy_change(){ GET_COMBODATA_TYPE_INT(create_enemy_change); } //int32_t i
30607 void FFScript::getComboData_directional_change_type(){ GET_COMBODATA_TYPE_INT(directional_change_type); } //byte j
30608 void FFScript::getComboData_distance_change_tiles(){ GET_COMBODATA_TYPE_INT(distance_change_tiles); } //int32_t k
30609 void FFScript::getComboData_dive_item(){ GET_COMBODATA_TYPE_INT(dive_item); } //int16_t l
30610 void FFScript::getComboData_dock(){ GET_COMBODATA_TYPE_INT(dock); } //byte m
30611 void FFScript::getComboData_fairy(){ GET_COMBODATA_TYPE_INT(fairy); } //byte n
30612 void FFScript::getComboData_ff_combo_attr_change(){ GET_COMBODATA_TYPE_INT(ff_combo_attr_change); } //byte o
30613 void FFScript::getComboData_foot_decorations_tile(){ GET_COMBODATA_TYPE_INT(foot_decorations_tile); } //int32_t p
30614 void FFScript::getComboData_foot_decorations_type(){ GET_COMBODATA_TYPE_INT(foot_decorations_type); } //byte q
30615 void FFScript::getComboData_hookshot_grab_point(){ GET_COMBODATA_TYPE_INT(hookshot_grab_point); } //byte r
30616 void FFScript::getComboData_ladder_pass(){ GET_COMBODATA_TYPE_INT(ladder_pass); } //byte s
30617 void FFScript::getComboData_lock_block_type(){ GET_COMBODATA_TYPE_INT(lock_block_type); } //byte t
30618 void FFScript::getComboData_lock_block_change(){ GET_COMBODATA_TYPE_INT(lock_block_change); } //int32_t u
30619 void FFScript::getComboData_magic_mirror_type(){ GET_COMBODATA_TYPE_INT(magic_mirror_type); } //byte v
30620 void FFScript::getComboData_modify_hp_amount(){ GET_COMBODATA_TYPE_INT(modify_hp_amount); } //int16_t w
30621 void FFScript::getComboData_modify_hp_delay(){ GET_COMBODATA_TYPE_INT(modify_hp_delay); } //byte x
30622 void FFScript::getComboData_modify_hp_type(){ GET_COMBODATA_TYPE_INT(modify_hp_type); } //byte y
30623 void FFScript::getComboData_modify_mp_amount(){ GET_COMBODATA_TYPE_INT(modify_mp_amount); } //int16_t z
30624 void FFScript::getComboData_modify_mp_delay(){ GET_COMBODATA_TYPE_INT(modify_mp_delay); } //byte aa
30625 void FFScript::getComboData_modify_mp_type(){ GET_COMBODATA_TYPE_INT(modify_mp_type); } //byte ab
30626 void FFScript::getComboData_no_push_blocks(){ GET_COMBODATA_TYPE_INT(no_push_blocks); } //byte ac
30627 void FFScript::getComboData_overhead(){ GET_COMBODATA_TYPE_INT(overhead); } //byte ad
30628 void FFScript::getComboData_place_enemy(){ GET_COMBODATA_TYPE_INT(place_enemy); } //byte ae
30629 void FFScript::getComboData_push_direction(){ GET_COMBODATA_TYPE_INT(push_direction); } //byte af
30630 void FFScript::getComboData_push_weight(){ GET_COMBODATA_TYPE_INT(push_weight); } //byte ag heavy or not
30631 void FFScript::getComboData_push_wait(){ GET_COMBODATA_TYPE_INT(push_wait); } //byte ah
30632 void FFScript::getComboData_pushed(){ GET_COMBODATA_TYPE_INT(pushed); } //byte ai
30633 void FFScript::getComboData_raft(){ GET_COMBODATA_TYPE_INT(raft); } //byte aj
30634 void FFScript::getComboData_reset_room(){ GET_COMBODATA_TYPE_INT(reset_room); } //byte ak
30635 void FFScript::getComboData_save_point_type(){ GET_COMBODATA_TYPE_INT(save_point_type); } //byte al
30636 void FFScript::getComboData_screen_freeze_type(){ GET_COMBODATA_TYPE_INT(screen_freeze_type); } //byte am
30637
30638 void FFScript::getComboData_secret_combo(){ GET_COMBODATA_TYPE_INT(secret_combo); } //byte an
30639 void FFScript::getComboData_singular(){ GET_COMBODATA_TYPE_INT(singular); } //byte ao
30640 void FFScript::getComboData_slow_movement(){ GET_COMBODATA_TYPE_INT(slow_movement); } //byte ap
30641 void FFScript::getComboData_statue_type(){ GET_COMBODATA_TYPE_INT(statue_type); } //byte aq
30642 void FFScript::getComboData_step_type(){ GET_COMBODATA_TYPE_INT(step_type); } //byte ar
30643 void FFScript::getComboData_step_change_to(){ GET_COMBODATA_TYPE_INT(step_change_to); } //int32_t as
30644 void FFScript::getComboData_strike_remnants(){ GET_COMBODATA_TYPE_INT(strike_remnants); } //int32_t au
30645 void FFScript::getComboData_strike_remnants_type(){ GET_COMBODATA_TYPE_INT(strike_remnants_type); } //byte av
30646 void FFScript::getComboData_strike_change(){ GET_COMBODATA_TYPE_INT(strike_change); } //int32_t aw
30647 void FFScript::getComboData_strike_item(){ GET_COMBODATA_TYPE_INT(strike_item); } //int16_t ax
30648 void FFScript::getComboData_touch_item(){ GET_COMBODATA_TYPE_INT(touch_item); } //int16_t ay
30649 void FFScript::getComboData_touch_stairs(){ GET_COMBODATA_TYPE_INT(touch_stairs); } //byte az
30650 void FFScript::getComboData_trigger_type(){ GET_COMBODATA_TYPE_INT(trigger_type); } //byte ba
30651 void FFScript::getComboData_trigger_sensitive(){ GET_COMBODATA_TYPE_INT(trigger_sensitive); } //byte bb
30652 void FFScript::getComboData_warp_type(){ GET_COMBODATA_TYPE_INT(warp_type); } //byte bc
30653 void FFScript::getComboData_warp_sensitive(){ GET_COMBODATA_TYPE_INT(warp_sensitive); } //byte bd
30654 void FFScript::getComboData_warp_direct(){ GET_COMBODATA_TYPE_INT(warp_direct); } //byte be
30655 void FFScript::getComboData_warp_location(){ GET_COMBODATA_TYPE_INT(warp_location); } //byte bf
30656 void FFScript::getComboData_water(){ GET_COMBODATA_TYPE_INT(water); } //byte bg
30657 void FFScript::getComboData_whistle(){ GET_COMBODATA_TYPE_INT(whistle); } //byte bh
30658 void FFScript::getComboData_win_game(){ GET_COMBODATA_TYPE_INT(win_game); } //byte bi
30659 void FFScript::getComboData_block_weapon_lvl(){ GET_COMBODATA_TYPE_INT(block_weapon_lvl); } //byte bj - max level of weapon to block
30660
30661 void FFScript::getComboData_tile(){ GET_COMBODATA_VAR_INT(tile); } //newcombo, word
30662 void FFScript::getComboData_flip(){ GET_COMBODATA_VAR_INT(flip); } //newcombo byte
30663
30664 void FFScript::getComboData_walk(){ GET_COMBODATA_VAR_INT(walk); } //newcombo byte
30665 void FFScript::getComboData_type(){ GET_COMBODATA_VAR_INT(type); } //newcombo byte
30666 void FFScript::getComboData_csets(){ GET_COMBODATA_VAR_INT(csets); } //newcombo byte
30667 void FFScript::getComboData_frames(){ GET_COMBODATA_VAR_INT(frames); } //newcombo byte
30668 void FFScript::getComboData_speed(){ GET_COMBODATA_VAR_INT(speed); } //newcombo byte
30669 void FFScript::getComboData_nextcombo(){ GET_COMBODATA_VAR_INT(nextcombo); } //newcombo word
30670 void FFScript::getComboData_nextcset(){ GET_COMBODATA_VAR_INT(nextcset); } //newcombo byte
30671 void FFScript::getComboData_flag(){ GET_COMBODATA_VAR_INT(flag); } //newcombo byte
30672 void FFScript::getComboData_skipanim(){ GET_COMBODATA_VAR_INT(skipanim); } //newcombo byte
30673 void FFScript::getComboData_nexttimer(){ GET_COMBODATA_VAR_INT(nexttimer); } //newcombo word
30674 void FFScript::getComboData_skipanimy(){ GET_COMBODATA_VAR_INT(skipanimy); } //newcombo byte
30675 void FFScript::getComboData_animflags(){ GET_COMBODATA_VAR_INT(animflags); } //newcombo byte
30676
30677
30678 //two inputs, one return
30679 void FFScript::getComboData_block_weapon(){ GET_COMBODATA_TYPE_INDEX(block_weapon,32); } //byte array[32] d (ID of LWeapon)
30680 void FFScript::getComboData_strike_weapons(){ GET_COMBODATA_TYPE_INDEX(strike_weapons,32); } //byte at, arr[32]
30681
30682 //Setters, two inputs no returns
30683
30684 void FFScript::setComboData_block_enemies(){ SET_COMBODATA_TYPE_INT(block_enemies,ZS_BYTE); } //byte a
30685 void FFScript::setComboData_block_hole(){ SET_COMBODATA_TYPE_INT(block_hole,ZS_BYTE); } //byte b
30686 void FFScript::setComboData_block_trigger(){ SET_COMBODATA_TYPE_INT(block_trigger,ZS_BYTE); } //byte c
30687 void FFScript::setComboData_conveyor_x_speed(){ SET_COMBODATA_TYPE_INT(conveyor_x_speed,ZS_SHORT); } //int16_t e
30688 void FFScript::setComboData_conveyor_y_speed(){ SET_COMBODATA_TYPE_INT(conveyor_y_speed,ZS_SHORT); } //int16_t f
30689 void FFScript::setComboData_create_enemy(){ SET_COMBODATA_TYPE_INT(create_enemy,ZS_WORD); } //word g
30690 void FFScript::setComboData_create_enemy_when(){ SET_COMBODATA_TYPE_INT(create_enemy_when,ZS_BYTE); } //byte h
30691 void FFScript::setComboData_create_enemy_change(){ SET_COMBODATA_TYPE_INT(create_enemy_change,ZS_LONG); } //int32_t i
30692 void FFScript::setComboData_directional_change_type(){ SET_COMBODATA_TYPE_INT(directional_change_type,ZS_BYTE); } //byte j
30693 void FFScript::setComboData_distance_change_tiles(){ SET_COMBODATA_TYPE_INT(distance_change_tiles,ZS_LONG); } //int32_t k
30694 void FFScript::setComboData_dive_item(){ SET_COMBODATA_TYPE_INT(dive_item,ZS_SHORT); } //int16_t l
30695 void FFScript::setComboData_dock(){ SET_COMBODATA_TYPE_INT(dock,ZS_BYTE); } //byte m
30696 void FFScript::setComboData_fairy(){ SET_COMBODATA_TYPE_INT(fairy,ZS_BYTE); } //byte n
30697 void FFScript::setComboData_ff_combo_attr_change(){ SET_COMBODATA_TYPE_INT(ff_combo_attr_change,ZS_BYTE); } //byte o
30698 void FFScript::setComboData_foot_decorations_tile(){ SET_COMBODATA_TYPE_INT(foot_decorations_tile,ZS_LONG); } //int32_t p
30699 void FFScript::setComboData_foot_decorations_type(){ SET_COMBODATA_TYPE_INT(foot_decorations_type,ZS_BYTE); } //byte q
30700 void FFScript::setComboData_hookshot_grab_point(){ SET_COMBODATA_TYPE_INT(hookshot_grab_point,ZS_BYTE); } //byte r
30701 void FFScript::setComboData_ladder_pass(){ SET_COMBODATA_TYPE_INT(ladder_pass,ZS_BYTE); } //byte s
30702 void FFScript::setComboData_lock_block_type(){ SET_COMBODATA_TYPE_INT(lock_block_type,ZS_BYTE); } //byte t
30703 void FFScript::setComboData_lock_block_change(){ SET_COMBODATA_TYPE_INT(lock_block_change,ZS_LONG); } //int32_t u
30704 void FFScript::setComboData_magic_mirror_type(){ SET_COMBODATA_TYPE_INT(magic_mirror_type,ZS_BYTE); } //byte v
30705 void FFScript::setComboData_modify_hp_amount(){ SET_COMBODATA_TYPE_INT(modify_hp_amount,ZS_SHORT); } //int16_t w
30706 void FFScript::setComboData_modify_hp_delay(){ SET_COMBODATA_TYPE_INT(modify_hp_delay,ZS_BYTE); } //byte x
30707 void FFScript::setComboData_modify_hp_type(){ SET_COMBODATA_TYPE_INT(modify_hp_type,ZS_BYTE); } //byte y
30708 void FFScript::setComboData_modify_mp_amount(){ SET_COMBODATA_TYPE_INT(modify_mp_amount,ZS_SHORT); } //int16_t z
30709 void FFScript::setComboData_modify_mp_delay(){ SET_COMBODATA_TYPE_INT(modify_mp_delay,ZS_BYTE); } //byte aa
30710 void FFScript::setComboData_modify_mp_type(){ SET_COMBODATA_TYPE_INT(modify_mp_type,ZS_BYTE); } //byte ab
30711 void FFScript::setComboData_no_push_blocks(){ SET_COMBODATA_TYPE_INT(no_push_blocks,ZS_BYTE); } //byte ac
30712 void FFScript::setComboData_overhead(){ SET_COMBODATA_TYPE_INT(overhead,ZS_BYTE); } //byte ad
30713 void FFScript::setComboData_place_enemy(){ SET_COMBODATA_TYPE_INT(place_enemy,ZS_BYTE); } //byte ae
30714 void FFScript::setComboData_push_direction(){ SET_COMBODATA_TYPE_INT(push_direction,ZS_BYTE); } //byte af
30715 void FFScript::setComboData_push_weight(){ SET_COMBODATA_TYPE_INT(push_weight,ZS_BYTE); } //byte ag heavy or not
30716 void FFScript::setComboData_push_wait(){ SET_COMBODATA_TYPE_INT(push_wait,ZS_BYTE); } //byte ah
30717 void FFScript::setComboData_pushed(){ SET_COMBODATA_TYPE_INT(pushed,ZS_BYTE); } //byte ai
30718 void FFScript::setComboData_raft(){ SET_COMBODATA_TYPE_INT(raft,ZS_BYTE); } //byte aj
30719 void FFScript::setComboData_reset_room(){ SET_COMBODATA_TYPE_INT(reset_room,ZS_BYTE); } //byte ak
30720 void FFScript::setComboData_save_point_type(){ SET_COMBODATA_TYPE_INT(save_point_type,ZS_BYTE); } //byte al
30721 void FFScript::setComboData_screen_freeze_type(){ SET_COMBODATA_TYPE_INT(screen_freeze_type,ZS_BYTE); } //byte am
30722
30723 void FFScript::setComboData_secret_combo(){ SET_COMBODATA_TYPE_INT(secret_combo,ZS_BYTE); } //byte an
30724 void FFScript::setComboData_singular(){ SET_COMBODATA_TYPE_INT(singular,ZS_BYTE); } //byte ao
30725 void FFScript::setComboData_slow_movement(){ SET_COMBODATA_TYPE_INT(slow_movement,ZS_BYTE); } //byte ap
30726 void FFScript::setComboData_statue_type(){ SET_COMBODATA_TYPE_INT(statue_type,ZS_BYTE); } //byte aq
30727 void FFScript::setComboData_step_type(){ SET_COMBODATA_TYPE_INT(step_type,ZS_BYTE); } //byte ar
30728 void FFScript::setComboData_step_change_to(){ SET_COMBODATA_TYPE_INT(step_change_to,ZS_LONG); } //int32_t as
30729
30730 void FFScript::setComboData_strike_remnants(){ SET_COMBODATA_TYPE_INT(strike_remnants,ZS_LONG); } //int32_t au
30731 void FFScript::setComboData_strike_remnants_type(){ SET_COMBODATA_TYPE_INT(strike_remnants_type,ZS_BYTE); } //byte av
30732 void FFScript::setComboData_strike_change(){ SET_COMBODATA_TYPE_INT(strike_change,ZS_LONG); } //int32_t aw
30733 void FFScript::setComboData_strike_item(){ SET_COMBODATA_TYPE_INT(strike_item,ZS_SHORT); } //int16_t ax
30734 void FFScript::setComboData_touch_item(){ SET_COMBODATA_TYPE_INT(touch_item,ZS_SHORT); } //int16_t ay
30735 void FFScript::setComboData_touch_stairs(){ SET_COMBODATA_TYPE_INT(touch_stairs,ZS_BYTE); } //byte az
30736 void FFScript::setComboData_trigger_type(){ SET_COMBODATA_TYPE_INT(trigger_type,ZS_BYTE); } //byte ba
30737 void FFScript::setComboData_trigger_sensitive(){ SET_COMBODATA_TYPE_INT(trigger_sensitive,ZS_BYTE); } //byte bb
30738 void FFScript::setComboData_warp_type(){ SET_COMBODATA_TYPE_INT(warp_type,ZS_BYTE); } //byte bc
30739 void FFScript::setComboData_warp_sensitive(){ SET_COMBODATA_TYPE_INT(warp_sensitive,ZS_BYTE); } //byte bd
30740 void FFScript::setComboData_warp_direct(){ SET_COMBODATA_TYPE_INT(warp_direct,ZS_BYTE); } //byte be
30741 void FFScript::setComboData_warp_location(){ SET_COMBODATA_TYPE_INT(warp_location,ZS_BYTE); } //byte bf
30742 void FFScript::setComboData_water(){ SET_COMBODATA_TYPE_INT(water,ZS_BYTE); } //byte bg
30743 void FFScript::setComboData_whistle(){ SET_COMBODATA_TYPE_INT(whistle,ZS_BYTE); } //byte bh
30744 void FFScript::setComboData_win_game(){ SET_COMBODATA_TYPE_INT(win_game,ZS_BYTE); } //byte bi
30745 void FFScript::setComboData_block_weapon_lvl(){ SET_COMBODATA_TYPE_INT(block_weapon_lvl,ZS_BYTE); } //byte bj - max level of weapon to block
30746
30747 //combobuf
30748 void FFScript::setComboData_tile(){ SET_COMBODATA_VAR_INT(tile,ZS_WORD); } //newcombo, word
30749 void FFScript::setComboData_flip(){ SET_COMBODATA_VAR_INT(flip,ZS_BYTE); } //newcombo byte
30750
30751 void FFScript::setComboData_walk(){ SET_COMBODATA_VAR_INT(walk,ZS_BYTE); } //newcombo byte
30752 void FFScript::setComboData_type(){ SET_COMBODATA_VAR_INT(type,ZS_BYTE); } //newcombo byte
30753 void FFScript::setComboData_csets(){ SET_COMBODATA_VAR_INT(csets,ZS_BYTE); } //newcombo byte
30754 void FFScript::setComboData_frames(){ SET_COMBODATA_VAR_INT(frames,ZS_BYTE); } //newcombo byte
30755 void FFScript::setComboData_speed(){ SET_COMBODATA_VAR_INT(speed,ZS_BYTE); } //newcombo byte
30756 void FFScript::setComboData_nextcombo(){ SET_COMBODATA_VAR_INT(nextcombo,ZS_WORD); } //newcombo word
30757 void FFScript::setComboData_nextcset(){ SET_COMBODATA_VAR_INT(nextcset,ZS_BYTE); } //newcombo byte
30758 void FFScript::setComboData_flag(){ SET_COMBODATA_VAR_INT(flag,ZS_BYTE); } //newcombo byte
30759 void FFScript::setComboData_skipanim(){ SET_COMBODATA_VAR_INT(skipanim,ZS_BYTE); } //newcombo byte
30760 void FFScript::setComboData_nexttimer(){ SET_COMBODATA_VAR_INT(nexttimer,ZS_WORD); } //newcombo word
30761 void FFScript::setComboData_skipanimy(){ SET_COMBODATA_VAR_INT(skipanimy,ZS_BYTE); } //newcombo byte
30762 void FFScript::setComboData_animflags(){ SET_COMBODATA_VAR_INT(animflags,ZS_BYTE); } //newcombo byte
30763
30764 //three inputs, no returns
30765 void FFScript::setComboData_block_weapon(int32_t v){ SET_COMBODATA_TYPE_INDEX(block_weapon,v,ZS_BYTE,32); } //byte array[32] d (ID of LWeapon)
30766 void FFScript::setComboData_strike_weapons(int32_t v){ SET_COMBODATA_TYPE_INDEX(strike_weapons,v,ZS_BYTE,32); } //byte at, arr[32]
30767
30768 //SpriteData Macros
30769 #define GET_SPRITEDATA_TYPE_INT(member) \
30770 { \
30771 int32_t ID = vbound((get_register(sarg2) / 10000),0,255);\
30772 set_register(sarg1, wpnsbuf[ID].member * 10000); \
30773 }
30774
30775 #define SET_SPRITEDATA_TYPE_INT(member, bound) \
30776 { \
30777 int32_t ID = get_register(sarg1) / 10000; \
30778 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
30779 if(ID < 1 || ID > 255) \
30780 set_register(sarg1, -10000); \
30781 else \
30782 wpnsbuf[ID].member = val; \
30783 }
30784
30785 #define SET_SPRITEDATA_TYPE_INT_NOBOUND(member) \
30786 { \
30787 int32_t ID = get_register(sarg1) / 10000; \
30788 int32_t val = get_register(sarg2) / 10000; \
30789 if(ID < 1 || ID > 255) \
30790 set_register(sarg1, -10000); \
30791 else \
30792 wpnsbuf[ID].member = val; \
30793 }
30794
30795
30796 void FFScript::getSpriteDataTile(){GET_SPRITEDATA_TYPE_INT(tile);}
30797 void FFScript::getSpriteDataMisc(){GET_SPRITEDATA_TYPE_INT(misc);}
30798 void FFScript::getSpriteDataCSets(){GET_SPRITEDATA_TYPE_INT(csets);}
30799 void FFScript::getSpriteDataFrames(){GET_SPRITEDATA_TYPE_INT(frames);}
30800 void FFScript::getSpriteDataSpeed(){GET_SPRITEDATA_TYPE_INT(speed);}
30801 void FFScript::getSpriteDataType(){GET_SPRITEDATA_TYPE_INT(type);}
30802
30803
30804
30805 void FFScript::setSpriteDataTile(){SET_SPRITEDATA_TYPE_INT(tile,ZS_WORD);}
30806 void FFScript::setSpriteDataMisc(){SET_SPRITEDATA_TYPE_INT(misc,ZS_CHAR);}
30807 void FFScript::setSpriteDataCSets(){SET_SPRITEDATA_TYPE_INT(csets,ZS_CHAR);}
30808 void FFScript::setSpriteDataFrames(){SET_SPRITEDATA_TYPE_INT(frames,ZS_CHAR);}
30809 void FFScript::setSpriteDataSpeed(){SET_SPRITEDATA_TYPE_INT(speed,ZS_CHAR);}
30810 void FFScript::setSpriteDataType(){SET_SPRITEDATA_TYPE_INT(type,ZS_CHAR);}
30811
30812
30813 2004 void FFScript::do_setMIDI_volume(int32_t m)
30814 {
30815 2004 master_volume(-1,(vbound(m,0,255)));
30816 2004 }
30817 2004 void FFScript::do_setMusic_volume(int32_t m)
30818 {
30819 2004 emusic_volume = vbound(m,0,255);
30820 2004 }
30821 2004 void FFScript::do_setDIGI_volume(int32_t m)
30822 {
30823 2004 master_volume((vbound(m,0,255)),-1);
30824 2004 }
30825 void FFScript::do_setSFX_volume(int32_t m)
30826 {
30827 sfx_volume = m;
30828 }
30829 void FFScript::do_setSFX_pan(int32_t m)
30830 {
30831 pan_style = vbound(m,0,3);
30832 }
30833 8 int32_t FFScript::do_getMIDI_volume()
30834 {
30835 8 return ((int32_t)midi_volume);
30836 }
30837 8 int32_t FFScript::do_getMusic_volume()
30838 {
30839 8 return ((int32_t)emusic_volume);
30840 }
30841 8 int32_t FFScript::do_getDIGI_volume()
30842 {
30843 8 return ((int32_t)digi_volume);
30844 }
30845 int32_t FFScript::do_getSFX_volume()
30846 {
30847 return ((int32_t)sfx_volume);
30848 }
30849 int32_t FFScript::do_getSFX_pan()
30850 {
30851 return ((int32_t)pan_style);
30852 }
30853
30854
30855 //Change Game Over Screen Values
30856 void FFScript::FFSetSaveScreenSetting()
30857 {
30858
30859 int32_t indx = get_register(sarg1) / 10000;
30860 int32_t value = get_register(sarg2) / 10000; //bounded in zelda.cpp
30861 if(indx < 0 || indx > 11)
30862 set_register(sarg1, -10000);
30863 else
30864 SetSaveScreenSetting(indx, value);
30865 }
30866
30867
30868
30869 void FFScript::FFChangeSubscreenText()
30870 {
30871
30872 int32_t index = get_register(sarg1) / 10000;
30873 int32_t arrayptr = get_register(sarg2);
30874
30875 if ( index < 0 || index > 3 )
30876 {
30877 al_trace("The index supplied to Game->SetSubscreenText() is invalid. The index specified was: %d /n", index);
30878 return;
30879 }
30880
30881 string filename_str;
30882 ArrayH::getString(arrayptr, filename_str, 73);
30883 ChangeSubscreenText(index,filename_str.c_str());
30884 }
30885
30886 20 void FFScript::SetItemMessagePlayed(int32_t itm)
30887 {
30888 20 game->item_messages_played[itm] = 1;
30889 20 }
30890 15 bool FFScript::GetItemMessagePlayed(int32_t itm)
30891 {
30892 15 return ((game->item_messages_played[itm] ) ? true : false);
30893 }
30894
30895 int32_t FFScript::getQRBit(int32_t rule)
30896 {
30897 return ( get_qr(rule) ? 1 : 0 );
30898 }
30899
30900 25881608 void FFScript::setHeroAction(int32_t a)
30901 {
30902 25881608 FF_hero_action = vbound(a, 0, 255);
30903 25881608 }
30904
30905 92677417 int32_t FFScript::getHeroAction()
30906 {
30907 92677417 int32_t special_action = Hero.getAction2();
30908
2/2
✓ Branch 0 taken 558880 times.
✓ Branch 1 taken 92118537 times.
92677417 if ( special_action != -1 ) return special_action; //spin, dive, charge
30909 92118537 else return FF_hero_action; //everything else
30910 92677417 }
30911
30912 1116 void FFScript::init()
30913 {
30914 1116 apply_qr_rules();
30915 1116 eventData.clear();
30916 1116 countGenScripts();
30917 // Some scripts can run even before ~Init (but only if qr_OLD_INIT_SCRIPT_TIMING is on), so figure out
30918 // the global register types ahead of time.
30919 1116 markGlobalRegisters();
30920
2/2
✓ Branch 0 taken 11160 times.
✓ Branch 1 taken 1116 times.
12276 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
30921 1116 temp_no_stepforward = 0;
30922 1116 nostepforward = 0;
30923 1116 numscriptdraws = 0;
30924 1116 skipscriptdraws = false;
30925 1116 max_ff_rules = qr_MAX;
30926 1116 coreflags = 0;
30927 1116 skip_ending_credits = 0;
30928 1116 music_update_cond = 0;
30929 1116 music_update_flags = 0;
30930 //quest_format : is this properly initialised?
30931
2/2
✓ Branch 0 taken 75888 times.
✓ Branch 1 taken 1116 times.
77004 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
30932
30933 1116 usr_midi_volume = midi_volume;
30934 1116 usr_digi_volume = digi_volume;
30935 1116 usr_sfx_volume = sfx_volume;
30936 1116 usr_music_volume = emusic_volume;
30937
30938 1116 usr_panstyle = pan_style;
30939 1116 FF_hero_action = 0;
30940 1116 enemy_removal_point[spriteremovalY1] = -32767;
30941 1116 enemy_removal_point[spriteremovalY2] = 32767;
30942 1116 enemy_removal_point[spriteremovalX1] = -32767;
30943 1116 enemy_removal_point[spriteremovalX2] = 32767;
30944 1116 enemy_removal_point[spriteremovalZ1] = -32767;
30945 1116 enemy_removal_point[spriteremovalZ2] = 32767;
30946
30947
2/2
✓ Branch 0 taken 4464 times.
✓ Branch 1 taken 1116 times.
5580 for ( int32_t q = 0; q < 4; q++ )
30948 {
30949 4464 FF_screenbounds[q] = 0;
30950 4464 FF_screen_dimensions[q] = 0;
30951 4464 FF_subscreen_dimensions[q] = 0;
30952 4464 FF_eweapon_removal_bounds[q] = 0;
30953 4464 FF_lweapon_removal_bounds[q] = 0;
30954 4464 }
30955
2/2
✓ Branch 0 taken 11160 times.
✓ Branch 1 taken 1116 times.
12276 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
30956 {
30957 11160 FF_clocks[q] = 0;
30958 11160 }
30959
2/2
✓ Branch 0 taken 22320 times.
✓ Branch 1 taken 1116 times.
23436 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
30960 {
30961 22320 ScriptDrawingRules[q] = 0;
30962 22320 }
30963
2/2
✓ Branch 0 taken 6696 times.
✓ Branch 1 taken 1116 times.
7812 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
30964 {
30965 6696 FF_UserMidis[q] = 0;
30966 6696 }
30967 1116 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
30968 1116 kb_typing_mode = false;
30969 1116 initIncludePaths();
30970 //clearRunningItemScripts();
30971 1116 ScrollingScreensAll.clear();
30972 1116 memset(ScrollingData, 0, sizeof(int32_t) * SZ_SCROLLDATA);
30973 1116 ScrollingData[SCROLLDATA_DIR] = -1;
30974 1116 user_rng_init();
30975 1116 clear_script_engine_data();
30976 1116 script_debug_handles.clear();
30977 1116 runtime_script_debug_handle = nullptr;
30978 1116 }
30979
30980 313 void FFScript::shutdown()
30981 {
30982 313 scriptEngineDatas.clear();
30983 313 objectRAM.clear();
30984 313 script_objects.clear();
30985 313 }
30986
30987 12 void FFScript::SetFFEngineFlag(int32_t flag, bool state)
30988 {
30989
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if ( state ) { coreflags |= flag; }
30990 else coreflags &= ~flag;
30991 12 }
30992
30993 void FFScript::setSubscreenScrollSpeed(byte n)
30994 {
30995 subscreen_scroll_speed = n;
30996 }
30997
30998 int32_t FFScript::getSubscreenScrollSpeed()
30999 {
31000 return (int32_t)subscreen_scroll_speed;
31001 }
31002
31003 void FFScript::do_greyscale(const bool v)
31004 {
31005 // This has been removed.
31006 }
31007
31008 void FFScript::do_monochromatic(const bool v)
31009 {
31010 // This has been removed.
31011 }
31012
31013 10680 static int convert_6bit_to_8bit_color_shift_arg(int v)
31014 {
31015 10680 int va = abs(v);
31016
2/2
✓ Branch 0 taken 10677 times.
✓ Branch 1 taken 3 times.
10680 if (va < 64)
31017 10677 return _rgb_scale_6[va] * sign(v);
31018
31019 3 int vdiv = va / 63;
31020 3 int vmod = va % 63;
31021 3 return (vdiv * 255 + _rgb_scale_6[vmod]) * sign(v);
31022 10680 }
31023
31024 void FFScript::gfxmonohue()
31025 {
31026 int32_t r = SH::read_stack(ri->sp + 3) / 10000;
31027 int32_t g = SH::read_stack(ri->sp + 2) / 10000;
31028 int32_t b = SH::read_stack(ri->sp + 1) / 10000;
31029 if (!scripting_use_8bit_colors)
31030 {
31031 r = convert_6bit_to_8bit_color_shift_arg(r);
31032 g = convert_6bit_to_8bit_color_shift_arg(g);
31033 b = convert_6bit_to_8bit_color_shift_arg(b);
31034 }
31035 bool m = (SH::read_stack(ri->sp + 0) / 10000);
31036 doGFXMonohue(r,g,b,m);
31037 }
31038
31039 66 void FFScript::clearTint()
31040 {
31041 66 doClearTint();
31042 66 }
31043
31044 3560 void FFScript::Tint()
31045 {
31046 3560 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
31047 3560 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
31048 3560 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
31049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3560 times.
3560 if (!scripting_use_8bit_colors)
31050 {
31051 3560 r = convert_6bit_to_8bit_color_shift_arg(r);
31052 3560 g = convert_6bit_to_8bit_color_shift_arg(g);
31053 3560 b = convert_6bit_to_8bit_color_shift_arg(b);
31054 3560 }
31055 3560 doTint(r,g,b);
31056 3560 }
31057
31058 void FFScript::do_fx_zap(const bool v)
31059 {
31060 int32_t out = SH::get_arg(sarg1, v);
31061
31062 if ( out ) { FFScript::do_zapout(); }
31063 else FFScript::do_zapin();
31064 }
31065
31066 void FFScript::do_fx_wavy(const bool v)
31067 {
31068 int32_t out = SH::get_arg(sarg1, v);
31069
31070 if ( out ) { FFScript::do_wavyout(); }
31071 else FFScript::do_wavyin();
31072 }
31073
31074 505826704 int32_t FFScript::getQuestHeaderInfo(int32_t type)
31075 {
31076 505826704 return quest_format[type];
31077 }
31078
31079 string get_filestr(const bool relative, bool is_file) //Used for 'FileSystem' functions.
31080 {
31081 int32_t strptr = get_register(sarg1);
31082 string user_path;
31083 ArrayH::getString(strptr, user_path, 512);
31084
31085 if (!relative)
31086 {
31087 user_path = user_path.substr(user_path.find_first_not_of('/'),string::npos); //Kill leading '/'
31088 size_t last = user_path.find_last_not_of('/');
31089 if(last!=string::npos)++last;
31090 user_path = user_path.substr(0,last); //Kill trailing '/'
31091 return user_path;
31092 }
31093
31094 if (auto r = parse_user_path(user_path, is_file); !r)
31095 {
31096 scripting_log_error_with_context("Error: {}", r.error());
31097 return "";
31098 } else return r.value();
31099 }
31100
31101 void FFScript::do_checkdir(const bool is_dir)
31102 {
31103 string resolved_path = get_filestr(get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE), false);
31104 set_register(sarg1, !resolved_path.empty() && checkPath(resolved_path.c_str(), is_dir) ? 10000 : 0);
31105 }
31106
31107 void FFScript::do_fs_remove()
31108 {
31109 string resolved_path = get_filestr(true, true);
31110 set_register(sarg1, !resolved_path.empty() && remove(resolved_path.c_str()) ? 0 : 10000);
31111 }
31112
31113 102 void FFScript::Play_Level_Music()
31114 {
31115 102 int32_t m = hero_scr->screen_midi;
31116
31117
1/6
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
102 switch(m)
31118 {
31119 case -2:
31120 music_stop();
31121 break;
31122
31123 case -1:
31124 102 play_DmapMusic();
31125 102 break;
31126
31127 case 1:
31128 jukebox(ZC_MIDI_OVERWORLD);
31129 break;
31130
31131 case 2:
31132 jukebox(ZC_MIDI_DUNGEON);
31133 break;
31134
31135 case 3:
31136 jukebox(ZC_MIDI_LEVEL9);
31137 break;
31138
31139 default:
31140 if(m>=4 && m<4+MAXCUSTOMMIDIS)
31141 jukebox(m+MIDIOFFSET_MAPSCR);
31142 else
31143 music_stop();
31144 }
31145 102 }
31146
31147 92 void FFScript::do_warp_ex(bool v)
31148 {
31149 92 int32_t zscript_array_ptr = SH::get_arg(sarg1, v);
31150 92 ArrayManager am(zscript_array_ptr);
31151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(am.invalid()) return;
31152 92 int32_t zscript_array_size = am.size();
31153
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 switch(zscript_array_size)
31154 {
31155 case 8: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags}
31156 case 9: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags, int32_t dir}
31157 {
31158 92 int32_t tmpwarp[9]={0};
31159
2/2
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 92 times.
828 for ( int32_t q = 0; q < 8; q++ )
31160 {
31161 736 tmpwarp[q] = (am.get(q)/10000);
31162 736 }
31163
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 66 times.
92 tmpwarp[wexDir] = zscript_array_size < 9 ? -1 : (am.get(8)/10000);\
31164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[1]) >= MAXDMAPS )
31165 {
31166 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", tmpwarp[1]);
31167 return;
31168 }
31169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[2]) >= MAPSCRS )
31170 {
31171 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", tmpwarp[2]);
31172 return;
31173 }
31174 //Extra sanity guard.
31175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( map_screen_index(DMaps[tmpwarp[1]].map, tmpwarp[2] + DMaps[tmpwarp[1]].xoff) >= (int32_t)TheMaps.size() )
31176 {
31177 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
31178 return;
31179 }
31180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(get_qr(qr_OLD_BROKEN_WARPEX_MUSIC))
31181 {
31182
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 88 times.
92 SETFLAG(tmpwarp[wexFlags],warpFlagFORCECONTINUEMUSIC,tmpwarp[wexFlags]&warpFlagFORCERESETMUSIC);
31183 92 TOGGLEFLAG(tmpwarp[wexFlags],warpFlagFORCERESETMUSIC);
31184 92 }
31185 //If we passed the sanity checks, populate the FFCore array and begin the action!
31186
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 92 times.
920 for ( int32_t q = 0; q < wexActive; q++ )
31187 {
31188 828 FFCore.warpex[q] = tmpwarp[q];
31189 828 }
31190 92 FFCore.warpex[wexActive] = 1;
31191 92 break;
31192 }
31193
31194 default:
31195 {
31196 scripting_log_error_with_context("Array supplied is the wrong size! The array size was: %d, and valid sizes are 8 and 9.", zscript_array_size);
31197 break;
31198 }
31199 }
31200 92 }
31201
31202 ///////////////////////////////
31203 //* SCRIPT ENGINE FUNCTIONS *//
31204 ////////////////////////////////////////////////////////////////////////////
31205
31206 void FFScript::clearRunningItemScripts()
31207 {
31208 //for ( byte q = 0; q < 256; q++ ) runningItemScripts[q] = 0;
31209 }
31210
31211
31212 11540 void FFScript::warpScriptCheck()
31213 {
31214
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11538 times.
11540 if(get_qr(qr_SCRIPTDRAWSINWARPS))
31215 {
31216 2 FFCore.runWarpScripts(false);
31217 2 FFCore.runWarpScripts(true); //Waitdraw
31218 2 }
31219
3/4
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 10702 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 836 times.
11538 else if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN) && doscript(ScriptType::ScriptedPassiveSubscreen))
31220 {
31221
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(DMaps[cur_dmap].passive_sub_script != 0)
31222 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
31223
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
836 if (waitdraw(ScriptType::ScriptedPassiveSubscreen) && DMaps[cur_dmap].passive_sub_script != 0 && doscript(ScriptType::ScriptedPassiveSubscreen))
31224 {
31225 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
31226 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31227 }
31228 836 }
31229 11540 }
31230
31231 4 void FFScript::runWarpScripts(bool waitdraw)
31232 {
31233
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(waitdraw)
31234 {
31235
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME))
31236 {
31237 1 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
31238 1 FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME) = false;
31239 1 }
31240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
31241 {
31242 2 FFCore.itemScriptEngineOnWaitdraw();
31243 2 }
31244
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptHEROACTIVE] )) && FFCore.waitdraw(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31245 {
31246 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
31247 FFCore.waitdraw(ScriptType::Hero) = false;
31248 }
31249
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31250 {
31251 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
31252 FFCore.waitdraw(ScriptType::DMap) = false;
31253 }
31254
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31255 {
31256 1 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
31257 1 FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31258 1 }
31259 //no doscript check here, becauseb of preload? Do we want to write doscript here? -Z 13th July, 2019
31260
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
31261 {
31262 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
31263
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if (scr->script != 0 && FFCore.waitdraw(ScriptType::Screen, scr->screen) && scr->preloadscript)
31264 {
31265 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
31266 FFCore.waitdraw(ScriptType::Screen, scr->screen) = 0;
31267 }
31268 2 });
31269 2 }
31270 2 }
31271 else
31272 {
31273
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.doscript(ScriptType::Global, GLOBAL_SCRIPT_GAME))
31274 {
31275 2 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
31276 2 }
31277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
31278 {
31279 2 FFCore.itemScriptEngine();
31280 2 }
31281
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ((!( FFCore.system_suspend[susptHEROACTIVE] )) && doscript(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255)
31282 {
31283 2 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
31284 2 }
31285
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && doscript(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31286 {
31287 2 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
31288 2 }
31289
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31290 {
31291 2 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
31292 2 }
31293
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
31294 {
31295 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
31296
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (scr->script != 0 && scr->preloadscript)
31297 {
31298 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
31299 }
31300 2 });
31301 2 }
31302 }
31303 4 }
31304
31305 34920089 void FFScript::runF6Engine()
31306 {
31307
5/6
✓ Branch 0 taken 34918283 times.
✓ Branch 1 taken 1806 times.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 34918237 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 46 times.
34920089 if(!Quit && (GameFlags&GAMEFLAG_TRYQUIT) && !(GameFlags&GAMEFLAG_F6SCRIPT_ACTIVE))
31308 {
31309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(globalscripts[GLOBAL_SCRIPT_F6]->valid())
31310 {
31311 //Incase this was called mid-another script, store ref data
31312 push_ri();
31313 //
31314 clear_bitmap(f6_menu_buf);
31315 blit(framebuf, f6_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31316 initZScriptGlobalScript(GLOBAL_SCRIPT_F6);
31317 int32_t openingwipe = black_opening_count;
31318 int32_t openingshape = black_opening_shape;
31319 black_opening_count = 0; //No opening wipe during F6 menu
31320 if(black_opening_shape==bosFADEBLACK) black_fade(0);
31321 GameFlags |= GAMEFLAG_F6SCRIPT_ACTIVE;
31322 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31323 pause_all_sfx();
31324
31325 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_F6);
31326 while (data.doscript)
31327 {
31328 script_drawing_commands.Clear();
31329 load_control_state();
31330 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
31331 if (data.waitdraw)
31332 {
31333 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
31334 data.waitdraw = false;
31335 }
31336 //Draw
31337 clear_bitmap(framebuf);
31338 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31339 doScriptMenuDraws();
31340 //
31341 advanceframe(true,true,false);
31342 if(Quit) break; //Something quit, end script running
31343 }
31344 resume_all_sfx();
31345 script_drawing_commands.Clear();
31346 //script_drawing_commands.push_commands(tmpDrawCommands);
31347 GameFlags &= ~GAMEFLAG_F6SCRIPT_ACTIVE;
31348 //Restore opening wipe
31349 black_opening_count = openingwipe;
31350 black_opening_shape = openingshape;
31351 if(openingshape == bosFADEBLACK)
31352 {
31353 refreshTints();
31354 memcpy(tempblackpal, RAMpal, PAL_SIZE*sizeof(RGB));
31355 }
31356 //Restore script refinfo
31357 pop_ri();
31358 //
31359 if(!Quit)
31360 {
31361 if(!get_qr(qr_NOCONTINUE))
31362 f_Quit(qQUIT);
31363 }
31364 }
31365 46 else f_Quit(qQUIT);
31366 46 zc_readkey(KEY_F6);
31367 46 GameFlags &= ~GAMEFLAG_TRYQUIT;
31368 46 }
31369 34920089 }
31370 33 void FFScript::runOnDeathEngine()
31371 {
31372
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2 times.
33 if(!playerscripts[SCRIPT_HERO_DEATH]->valid()) return; //No script to run
31373 2 clear_bitmap(script_menu_buf);
31374 2 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31375 2 initZScriptHeroScripts();
31376 2 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31377 2 kill_sfx(); //No need to pause/resume; the player is dead.
31378 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31379
31380 2 auto& data = get_script_engine_data(ScriptType::Hero);
31381
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 803 times.
✓ Branch 2 taken 803 times.
✓ Branch 3 taken 2 times.
805 while (data.doscript && !Quit)
31382 {
31383 803 script_drawing_commands.Clear();
31384 803 load_control_state();
31385 803 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
31386
1/2
✓ Branch 0 taken 803 times.
✗ Branch 1 not taken.
803 if (data.waitdraw)
31387 {
31388 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
31389 data.waitdraw = false;
31390 }
31391 //Draw
31392 803 clear_bitmap(framebuf);
31393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 803 times.
803 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31394 803 doScriptMenuDraws();
31395 //
31396 803 advanceframe(true);
31397 }
31398 2 script_drawing_commands.Clear();
31399 //script_drawing_commands.push_commands(tmpDrawCommands);
31400 2 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31401 33 }
31402 422 void FFScript::runOnLaunchEngine()
31403 {
31404
2/2
✓ Branch 0 taken 417 times.
✓ Branch 1 taken 5 times.
422 if(!globalscripts[GLOBAL_SCRIPT_ONLAUNCH]->valid()) return; //No script to run
31405 //Do NOT blit the prior screen to this bitmap; that would be the TITLE SCREEN.
31406 5 clear_to_color(script_menu_buf,BLACK);
31407 5 initZScriptGlobalScript(GLOBAL_SCRIPT_ONLAUNCH);
31408 5 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31409 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31410
31411 5 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH);
31412
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
10 while (data.doscript && !Quit)
31413 {
31414 5 script_drawing_commands.Clear();
31415 5 load_control_state();
31416 5 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
31417
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (data.waitdraw)
31418 {
31419 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
31420 data.waitdraw = false;
31421 }
31422 //Draw
31423 5 clear_bitmap(framebuf);
31424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31425
31426 5 doScriptMenuDraws();
31427 //
31428 5 advanceframe(true);
31429 }
31430 5 script_drawing_commands.Clear();
31431 //script_drawing_commands.push_commands(tmpDrawCommands);
31432 5 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31433 422 }
31434 10 bool FFScript::runGenericFrozenEngine(const word script, const int32_t *init_data)
31435 {
31436 10 user_genscript& scr = user_genscript::get(script);
31437
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if(script < 1 || script >= NUMSCRIPTSGENERIC) return false;
31438
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(init_data)
31439 {
31440 for(int q = 0; q < 8; ++q)
31441 scr.initd[q] = init_data[q];
31442 }
31443
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!genericscripts[script]->valid()) return false; //No script to run
31444
31445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(gen_frozen_index >= 400) // Experimentally tested to crash (stack overflow) at 500 for me -Em
31446 {
31447 Z_scripterrlog("Failed to run frozen generic script; too many (%zu) frozen scripts running already! Possible infinite recursion?\n", gen_frozen_index);
31448 return false;
31449 }
31450 //Store script refinfo
31451 10 push_ri();
31452 10 int local_i = int(gen_frozen_index++);
31453 10 reset_script_engine_data(ScriptType::GenericFrozen, local_i);
31454 //run script
31455 10 uint32_t fl = GameFlags & GAMEFLAG_SCRIPTMENU_ACTIVE;
31456 10 BITMAP* tmpbuf = script_menu_buf;
31457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
31458 {
31459 script_menu_buf = create_bitmap_ex(8, framebuf->w, framebuf->h);
31460 }
31461 10 clear_bitmap(script_menu_buf);
31462 10 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31463 10 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31464 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31465
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1542 times.
✓ Branch 2 taken 1542 times.
✓ Branch 3 taken 10 times.
1552 while(doscript(ScriptType::GenericFrozen, local_i) && !Quit)
31466 {
31467 1542 script_drawing_commands.Clear();
31468 1542 load_control_state();
31469 1542 ZScriptVersion::RunScript(ScriptType::GenericFrozen, script, local_i);
31470 //Draw
31471 1542 clear_bitmap(framebuf);
31472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1542 times.
1542 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31473 1542 doScriptMenuDraws();
31474 //
31475 1542 advanceframe(true);
31476 }
31477 10 script_drawing_commands.Clear();
31478 //script_drawing_commands.push_commands(tmpDrawCommands);
31479 //clear
31480 10 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
31482 {
31483 GameFlags |= fl;
31484 destroy_bitmap(script_menu_buf);
31485 script_menu_buf = tmpbuf;
31486 }
31487 10 clear_script_engine_data(ScriptType::GenericFrozen, local_i);
31488 10 --gen_frozen_index;
31489 //Restore script refinfo
31490 10 pop_ri();
31491 10 return true;
31492 10 }
31493
31494 1424 bool FFScript::runScriptedActiveSusbcreen()
31495 {
31496 1424 word activesubscript = DMaps[cur_dmap].active_sub_script;
31497
3/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1383 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
1424 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return false; //No script to run
31498 41 word passivesubscript = DMaps[cur_dmap].passive_sub_script;
31499 41 word dmapactivescript = DMaps[cur_dmap].script;
31500 41 clear_bitmap(script_menu_buf);
31501 41 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31502 41 initZScriptScriptedActiveSubscreen();
31503 41 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31504 41 word script_dmap = cur_dmap;
31505 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31506 41 pause_all_sfx();
31507 41 auto& data = get_script_engine_data(ScriptType::ScriptedActiveSubscreen);
31508
4/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6772 times.
✓ Branch 2 taken 6772 times.
✓ Branch 3 taken 41 times.
6813 while (data.doscript && !Quit)
31509 {
31510 6772 script_drawing_commands.Clear();
31511 6772 load_control_state();
31512
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6772 if(get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap))
31513 {
31514 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
31515 }
31516
4/6
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 6632 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 140 times.
6772 if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen))
31517 {
31518 140 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
31519 140 }
31520 6772 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
31521
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6772 if(waitdraw(ScriptType::DMap) && (get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap)))
31522 {
31523 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
31524 waitdraw(ScriptType::DMap) = false;
31525 }
31526
5/8
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 6633 times.
✓ Branch 2 taken 139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139 times.
6772 if(waitdraw(ScriptType::ScriptedPassiveSubscreen) && (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen)))
31527 {
31528 139 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
31529 139 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31530 139 }
31531
3/4
✓ Branch 0 taken 5472 times.
✓ Branch 1 taken 1300 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5472 times.
6772 if (data.waitdraw && data.doscript)
31532 {
31533 5472 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
31534 5472 data.waitdraw = false;
31535 5472 }
31536 //Draw
31537 6772 clear_bitmap(framebuf);
31538
2/4
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6772 times.
6772 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
31539 6772 doScriptMenuDraws();
31540 //
31541 6772 advanceframe(true);
31542 //Handle warps; run game_loop once!
31543
1/2
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
6772 if(cur_dmap != script_dmap)
31544 {
31545 activesubscript = DMaps[cur_dmap].active_sub_script;
31546 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return true; //No script to run
31547 passivesubscript = DMaps[cur_dmap].passive_sub_script;
31548 dmapactivescript = DMaps[cur_dmap].script;
31549 script_dmap = cur_dmap;
31550 //Reset the background image
31551 game_loop();
31552 clear_bitmap(script_menu_buf);
31553 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31554 //Now loop without advancing frame, so that the subscreen script can draw immediately.
31555 }
31556 }
31557 41 resume_all_sfx();
31558 41 script_drawing_commands.Clear();
31559 //script_drawing_commands.push_commands(tmpDrawCommands);
31560 41 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31561 41 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
31562 41 return true;
31563 1424 }
31564 1078 bool FFScript::runOnMapScriptEngine()
31565 {
31566 1078 word onmap_script = DMaps[cur_dmap].onmap_script;
31567
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1075 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
1078 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return false; //No script to run
31568 3 clear_bitmap(script_menu_buf);
31569 3 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31570 3 initZScriptOnMapScript();
31571 3 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31572 3 word script_dmap = cur_dmap;
31573 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31574 3 pause_all_sfx();
31575
31576 3 auto& data = get_script_engine_data(ScriptType::OnMap);
31577
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 3 times.
117 while (data.doscript && !Quit)
31578 {
31579 114 script_drawing_commands.Clear();
31580 114 load_control_state();
31581 114 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
31582
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (data.waitdraw && data.doscript)
31583 {
31584 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
31585 data.waitdraw = false;
31586 }
31587 //Draw
31588 114 clear_bitmap(framebuf);
31589
2/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
31590 114 doScriptMenuDraws();
31591 //
31592 114 advanceframe(true);
31593 //Handle warps; run game_loop once!
31594
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if(cur_dmap != script_dmap)
31595 {
31596 onmap_script = DMaps[cur_dmap].onmap_script;
31597 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return true; //No script to run
31598 script_dmap = cur_dmap;
31599 //Reset the background image
31600 game_loop();
31601 clear_bitmap(script_menu_buf);
31602 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31603 //Now loop without advancing frame, so that the subscreen script can draw immediately.
31604 }
31605 }
31606 3 resume_all_sfx();
31607 3 script_drawing_commands.Clear();
31608 //script_drawing_commands.push_commands(tmpDrawCommands);
31609 3 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31610 3 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
31611 3 return true;
31612 1078 }
31613
31614 9236 void FFScript::doScriptMenuDraws()
31615 {
31616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9236 times.
9236 BITMAP* menu_buf = ((GameFlags & GAMEFLAG_F6SCRIPT_ACTIVE) != 0) ? f6_menu_buf : script_menu_buf;
31617 9236 blit(menu_buf, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31618 //Script draws
31619 9236 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
31620 9236 }
31621
31622 269 void FFScript::runOnSaveEngine()
31623 {
31624
1/2
✓ Branch 0 taken 269 times.
✗ Branch 1 not taken.
269 if(globalscripts[GLOBAL_SCRIPT_ONSAVE]->valid())
31625 {
31626 push_ri();
31627 //Prevent getting here via Quit from causing a forced-script-quit after 1000 commands!
31628 int32_t tQuit = Quit;
31629 Quit = 0;
31630 //
31631 initZScriptGlobalScript(GLOBAL_SCRIPT_ONSAVE);
31632 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONSAVE, GLOBAL_SCRIPT_ONSAVE);
31633 //
31634 pop_ri();
31635 Quit = tQuit;
31636 }
31637 269 }
31638
31639 15941999 bool FFScript::itemScriptEngine()
31640 {
31641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15941999 times.
15941999 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
31642
2/2
✓ Branch 0 taken 4081151744 times.
✓ Branch 1 taken 15941999 times.
4097093743 for ( int32_t q = 0; q < MAXITEMS; q++ )
31643 {
31644
31645
3/4
✓ Branch 0 taken 29532190 times.
✓ Branch 1 taken 4051619554 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29532190 times.
4081151744 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
31646
31647 29532190 auto& data = get_script_engine_data(ScriptType::Item, q);
31648
2/2
✓ Branch 0 taken 14167 times.
✓ Branch 1 taken 29518023 times.
29532190 if ( data.doscript < 1 ) continue;
31649
31650 //Passive items
31651
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14167 times.
14167 if (((itemsbuf[q].flags&item_passive_script)))
31652 {
31653 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
31654 {
31655 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
31656 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
31657 data.doscript = 0;
31658 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31659 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31660 {
31661 data.clear_ref();
31662 data.waitdraw = false;
31663 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31664 }
31665 }
31666 }
31667 else
31668 {
31669
31670 //Normal Items
31671 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
31672 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
31673 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
31674 same item script (again) that frame, and insteads increments item_doscript to '2'.
31675 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
31676 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
31677 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
31678 This allows passive item scripts to function.
31679 */
31680
31681 14167 auto& data = get_script_engine_data(ScriptType::Item, q);
31682
31683
2/2
✓ Branch 0 taken 662 times.
✓ Branch 1 taken 13505 times.
14167 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
31684 {
31685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 662 times.
662 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
31686 {
31687 662 data.doscript = 2;
31688 662 }
31689 662 }
31690
1/2
✓ Branch 0 taken 13505 times.
✗ Branch 1 not taken.
13505 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
31691 {
31692 13505 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31693 13505 }
31694 else if (data.doscript == 3) //Run via itemdata->RunScript
31695 {
31696 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
31697 {
31698 data.doscript = 2; //Reduce to normal run status
31699 }
31700 else
31701 {
31702 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
31703 data.doscript = 0;
31704 }
31705 }
31706 else if(data.doscript==4) //Item set itself false, kill script and clear data here
31707 {
31708 data.doscript = 0;
31709 }
31710
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 677 times.
14167 if(data.doscript==0) //Item script ended. Clear the data, if any remains.
31711 {
31712 677 data.clear_ref();
31713 677 data.waitdraw = false;
31714 677 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31715 677 }
31716 }
31717 14167 }
31718 15941999 return false;
31719 15941999 }
31720
31721 16431992 bool FFScript::itemScriptEngineOnWaitdraw()
31722 {
31723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16431992 times.
16431992 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
31724
2/2
✓ Branch 0 taken 4206589952 times.
✓ Branch 1 taken 16431992 times.
4223021944 for ( int32_t q = 0; q < MAXITEMS; q++ )
31725 {
31726
3/4
✓ Branch 0 taken 31392395 times.
✓ Branch 1 taken 4175197557 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31392395 times.
4206589952 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
31727
31728 31392395 auto& data = get_script_engine_data(ScriptType::Item, q);
31729
31730
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 31378904 times.
31392395 if ( data.doscript < 1 ) continue;
31731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13491 times.
13491 if (!data.waitdraw) continue;
31732 else data.waitdraw = false;
31733
31734 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
31735 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
31736 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
31737 same item script (again) that frame, and insteads increments item_doscript to '2'.
31738 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
31739 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
31740 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
31741 This allows passive item scripts to function.
31742 */
31743 //Passive items
31744 if ((itemsbuf[q].flags&item_passive_script))
31745 {
31746 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
31747 {
31748 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
31749 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
31750 data.doscript = 0;
31751 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31752 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31753 {
31754 data.clear_ref();
31755 data.waitdraw = false;
31756 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31757 }
31758 }
31759 }
31760 else
31761 {
31762 //Normal items
31763 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
31764 {
31765 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
31766 {
31767 data.doscript = 2;
31768 }
31769 else data.doscript = 0;
31770 }
31771 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
31772 {
31773 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31774 }
31775 else if (data.doscript == 3) //Run via itemdata->RunScript
31776 {
31777 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
31778 {
31779 data.doscript = 2; //Reduce to normal run status
31780 }
31781 else
31782 {
31783 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
31784 data.doscript = 0;
31785 }
31786 }
31787 else if(data.doscript==4) //Item set itself false, kill script and clear data here.
31788 {
31789 data.doscript = 0;
31790 }
31791 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31792 {
31793 data.clear_ref();
31794 data.waitdraw = false;
31795 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31796 }
31797 }
31798 }
31799 16431992 return false;
31800 16431992 }
31801 14768522 void FFScript::npcScriptEngineOnWaitdraw()
31802 {
31803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14768522 times.
14768522 if ( FFCore.system_suspend[susptNPCSCRIPTS] ) return;
31804 14768522 guys.run_script(MODE_WAITDRAW);
31805 14768522 }
31806
31807 14306378 void FFScript::eweaponScriptEngine()
31808 {
31809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14306378 times.
14306378 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
31810 14306378 Ewpns.run_script(MODE_NORMAL);
31811 14306378 }
31812
31813 14768522 void FFScript::lweaponScriptEngineOnWaitdraw()
31814 {
31815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14768522 times.
14768522 if ( FFCore.system_suspend[susptLWEAPONSCRIPTS] ) return;
31816 14768522 Lwpns.run_script(MODE_WAITDRAW);
31817 14768522 }
31818
31819 14796476 void FFScript::eweaponScriptEngineOnWaitdraw()
31820 {
31821
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 14796466 times.
14796476 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
31822 14796466 Ewpns.run_script(MODE_WAITDRAW);
31823 14796476 }
31824
31825 14309004 void FFScript::itemSpriteScriptEngine()
31826 {
31827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14309004 times.
14309004 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
31828 14309004 items.run_script(MODE_NORMAL);
31829 14309004 }
31830
31831 14798994 void FFScript::itemSpriteScriptEngineOnWaitdraw()
31832 {
31833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14798994 times.
14798994 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
31834 14798994 items.run_script(MODE_WAITDRAW);
31835 14798994 }
31836
31837
31838 15 int32_t FFScript::getTime(int32_t type)
31839 {
31840 //struct tm *tm_struct = localtime(time(NULL));
31841 struct tm * tm_struct;
31842 time_t sysRTC;
31843 15 time (&sysRTC);
31844 15 tm_struct = localtime (&sysRTC);
31845 15 int32_t rval = -1;
31846
31847
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
15 switch(type)
31848 {
31849 case curyear:
31850 {
31851 //Year format starts at 1900, yeat
31852 //A raw read of '2018' would be '118', so we add 1900 to it to derive the actual year.
31853 3 rval = tm_struct->tm_year + 1900; break;
31854
31855 }
31856 case curmonth:
31857 {
31858 //Months start at 0, but we want 1->12
31859 rval = tm_struct->tm_mon +1; break;
31860 }
31861 case curday_month:
31862 {
31863 rval = tm_struct->tm_mday; break;
31864 }
31865 case curday_week:
31866 {
31867 //It seems that weekdays are a value range of 1 to 7.
31868 rval = tm_struct->tm_wday; break;
31869 }
31870 case curhour:
31871 {
31872 3 rval = tm_struct->tm_hour; break;
31873 }
31874 case curminute:
31875 {
31876 3 rval = tm_struct->tm_min; break;
31877 }
31878 case cursecond:
31879 {
31880 3 rval = tm_struct->tm_sec; break;
31881 }
31882 case curdayyear:
31883 {
31884 //The day (n/365) out of the entire year.
31885 3 rval = tm_struct->tm_yday; break;
31886 }
31887 case curDST:
31888 {
31889 //Returns if the user is in a Time Zone with Daylight TIme of some sort.
31890 //View the time.h docs for the actual values of this struct element.
31891 rval = tm_struct->tm_isdst;; break;
31892 }
31893 default:
31894 {
31895 al_trace("Invalid category passed to GetSystemTime(%d)\n",type);
31896 rval = -1; break;
31897 }
31898
31899 }
31900 15 return rval;
31901 }
31902
31903 10 void FFScript::do_lweapon_delete()
31904 {
31905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(0!=(s=checkLWpn(ri->lwpn)))
31906 {
31907
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(s==Hero.lift_wpn)
31908 {
31909 delete s;
31910 Hero.lift_wpn = nullptr;
31911 }
31912 10 else Lwpns.del(s);
31913 10 }
31914 10 }
31915
31916 46 void FFScript::do_eweapon_delete()
31917 {
31918
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(0!=(s=checkEWpn(ri->ewpn)))
31919 {
31920 46 Ewpns.del(s);
31921 46 }
31922 46 }
31923
31924 1116 void FFScript::updateIncludePaths()
31925 {
31926 1116 includePaths.clear();
31927 1116 int32_t pos = 0;
31928
2/2
✓ Branch 0 taken 3864 times.
✓ Branch 1 taken 1116 times.
4980 for ( int32_t q = 0; includePathString[pos]; ++q )
31929 {
31930 3864 int32_t dest = 0;
31931 3864 char buf[2048] = {0};
31932
4/4
✓ Branch 0 taken 3778 times.
✓ Branch 1 taken 79588 times.
✓ Branch 2 taken 79502 times.
✓ Branch 3 taken 3864 times.
83366 while(includePathString[pos] != ';' && includePathString[pos])
31933 {
31934 79502 buf[dest] = includePathString[pos];
31935 79502 ++pos;
31936 79502 ++dest;
31937 }
31938 3864 ++pos;
31939
1/2
✓ Branch 0 taken 3864 times.
✗ Branch 1 not taken.
3864 std::string str(buf);
31940
1/2
✓ Branch 0 taken 3864 times.
✗ Branch 1 not taken.
3864 includePaths.push_back(str);
31941 3864 }
31942 1116 }
31943
31944 1116 void FFScript::initIncludePaths()
31945 {
31946 1116 memset(includePathString,0,sizeof(includePathString));
31947 1116 FILE* f = fopen("includepaths.txt", "r");
31948
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1030 times.
1116 if(f)
31949 {
31950 86 int32_t pos = 0;
31951 int32_t c;
31952 86 do
31953 {
31954 55556 c = fgetc(f);
31955
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 55470 times.
55556 if(c!=EOF)
31956 55470 includePathString[pos++] = c;
31957
2/2
✓ Branch 0 taken 55470 times.
✓ Branch 1 taken 86 times.
111112 }
31958
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 55470 times.
55556 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
31959
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(pos<MAX_INCLUDE_PATH_CHARS)
31960 86 includePathString[pos] = '\0';
31961 86 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
31962 86 fclose(f);
31963 86 }
31964 1030 else strcpy(includePathString, "include/;headers/;scripts/;");
31965 1116 al_trace("Full path string is: ");
31966 1116 safe_al_trace(includePathString);
31967 1116 al_trace("\n");
31968 1116 updateIncludePaths();
31969
31970
2/2
✓ Branch 0 taken 3864 times.
✓ Branch 1 taken 1116 times.
4980 for ( size_t q = 0; q < includePaths.size(); ++q )
31971 {
31972 3864 al_trace("Include path %zu: ",q);
31973 3864 safe_al_trace(includePaths.at(q));
31974 3864 al_trace("\n");
31975 3864 }
31976 1116 }
31977
31978 10 bool FFScript::checkExtension(std::string &filename, const std::string &extension)
31979 //inline bool checkExtension(std::string filename, std::string extension)
31980 {
31981 10 int32_t dot = filename.find_last_of(".");
31982
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
10 std::string exten = (dot == std::string::npos ? "" : filename.substr(dot, filename.length() - dot));
31983 10 return exten == extension;
31984 10 }
31985
31986
31987 void FFScript::do_loadgamestructs(const bool v, const bool v2)
31988 {
31989 int32_t arrayptr = SH::get_arg(sarg1, v);
31990 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
31991 //Bitwise OR sections together
31992 string strA;
31993 ArrayH::getString(arrayptr, strA, 256);
31994 int32_t temp_sram_flags = section_id; int32_t sram_version = 0;
31995
31996 if ( FFCore.checkExtension(strA, ".zcsram") )
31997 {
31998 PACKFILE *f = pack_fopen_password(strA.c_str(),F_READ, "");
31999 if (f)
32000 {
32001 p_igetl(&sram_version,f);
32002 p_igetl(&section_id,f);
32003 if ( sram_version > SRAM_VERSION ) //file version is greater than programme current version.
32004 {
32005 Z_scripterrlog("SRAM Version is from a version of ZC newer than the running version and cannot be loaded.\n");
32006 return;
32007 }
32008 if ( section_id != temp_sram_flags )
32009 {
32010 Z_scripterrlog("Reading an SRAM file with a section flag mismatch!\nThe file section flags are (%d) and the specified flagset is (%d).\nThis may cause errors!\n", section_id, temp_sram_flags);
32011 }
32012
32013 if ( !section_id || section_id&svGUYS ) FFCore.read_enemies(f,sram_version);
32014 if ( !section_id || section_id&svITEMS )FFCore.read_items(f,sram_version);
32015 if ( !section_id || section_id&svWEAPONS ) FFCore.read_weaponsprtites(f,sram_version);
32016 if ( !section_id || section_id&svCOMBOS )
32017 {
32018 reset_all_combo_animations();
32019 FFCore.read_combos(f,sram_version);
32020 }
32021 if ( !section_id || section_id&svDMAPS ) FFCore.read_dmaps(f,sram_version);
32022 if ( !section_id || section_id&svMAPSCR ) FFCore.read_mapscreens(f,sram_version);
32023 pack_fclose(f);
32024
32025 set_register(sarg1, 10000);
32026 }
32027 else
32028 {
32029 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
32030 set_register(sarg1, -10000);
32031 }
32032 }
32033 else
32034 {
32035 Z_scripterrlog("Tried to read a .zcsram file, but the file lacked the ..zcsram extension!\n");
32036 set_register(sarg1, -20000);
32037
32038 }
32039 }
32040
32041 110 void FFScript::do_savegamestructs(const bool v, const bool v2)
32042 {
32043 110 int32_t arrayptr = SH::get_arg(sarg1, v);
32044 110 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
32045 //Bitwise OR sections together
32046 110 string strA;
32047
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 100 times.
110 ArrayH::getString(arrayptr, strA, 256);
32048 10 int32_t cycles = 0;
32049
32050
3/6
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 if ( FFCore.checkExtension(strA, ".zcsram") )
32051 {
32052
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 PACKFILE *f = pack_fopen_password(strA.c_str(),F_WRITE, "");
32053
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (f)
32054 {
32055
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(SRAM_VERSION,f);
32056
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(section_id,f);
32057
32058
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( !section_id || section_id&svGUYS ) FFCore.write_enemies(f,SRAM_VERSION);
32059 if ( !section_id || section_id&svITEMS ) FFCore.write_items(f,SRAM_VERSION);
32060 if ( !section_id || section_id&svWEAPONS ) FFCore.write_weaponsprtites(f,SRAM_VERSION);
32061 if ( !section_id || section_id&svCOMBOS )
32062 {
32063
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 reset_all_combo_animations();
32064 FFCore.write_combos(f,SRAM_VERSION);
32065 }
32066 if ( !section_id || section_id&svDMAPS ) FFCore.write_dmaps(f,SRAM_VERSION);
32067 if ( !section_id || section_id&svMAPSCR ) FFCore.write_mapscreens(f,SRAM_VERSION);
32068
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 pack_fclose(f);
32069
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 set_register(sarg1, 10000);
32070 10 }
32071 else
32072 {
32073 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
32074 set_register(sarg1, -10000);
32075 }
32076 10 }
32077 else
32078 {
32079 Z_scripterrlog("Tried to write a .zcsram file, but the file lacked the ..zcsram extension!\n");
32080 set_register(sarg1, -20000);
32081 }
32082 210 }
32083
32084 2541 void FFScript::do_strcmp()
32085 {
32086 2541 int32_t arrayptr_a = ri->d[rINDEX];
32087 2541 int32_t arrayptr_b = ri->d[rINDEX2];
32088 2541 string strA;
32089 2541 string strB;
32090
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_a, strA);
32091
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_b, strB);
32092
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 set_register(sarg1, (strcmp(strA.c_str(), strB.c_str()) * 10000));
32093 2541 }
32094
32095 void FFScript::do_stricmp()
32096 {
32097 int32_t arrayptr_a = ri->d[rINDEX];
32098 int32_t arrayptr_b = ri->d[rINDEX2];
32099 string strA;
32100 string strB;
32101 ArrayH::getString(arrayptr_a, strA);
32102 ArrayH::getString(arrayptr_b, strB);
32103 set_register(sarg1, (stricmp(strA.c_str(), strB.c_str()) * 10000));
32104 }
32105
32106 1 void FFScript::do_LowerToUpper(const bool v)
32107 {
32108 1 int32_t arrayptr_a = get_register(sarg1);
32109 1 string strA;
32110
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::getString(arrayptr_a, strA);
32111
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (char& c : strA)
32112 5 c = std::toupper(c);
32113
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::setArray(arrayptr_a, strA);
32114
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_register(sarg1, 10000); // used to return 0 if string was empty.
32115 1 }
32116
32117 void FFScript::do_UpperToLower(const bool v)
32118 {
32119 int32_t arrayptr_a = get_register(sarg1);
32120 string strA;
32121 ArrayH::getString(arrayptr_a, strA);
32122 for (char& c : strA)
32123 c = std::tolower(c);
32124 ArrayH::setArray(arrayptr_a, strA);
32125 set_register(sarg1, 10000); // used to return 0 if string was empty.
32126 }
32127
32128 void FFScript::do_getnpcscript()
32129 {
32130 do_get_script_index_by_name(name_to_slot_index_npcmap);
32131 }
32132
32133 void FFScript::do_getcomboscript()
32134 {
32135 do_get_script_index_by_name(name_to_slot_index_comboscriptmap);
32136 }
32137
32138 137117 void FFScript::do_getgenericscript()
32139 {
32140 137117 do_get_script_index_by_name(name_to_slot_index_genericmap);
32141 137117 }
32142
32143 1707 void FFScript::do_getlweaponscript()
32144 {
32145 1707 do_get_script_index_by_name(name_to_slot_index_lwpnmap);
32146 1707 }
32147 1664 void FFScript::do_geteweaponscript()
32148 {
32149 1664 do_get_script_index_by_name(name_to_slot_index_ewpnmap);
32150 1664 }
32151 void FFScript::do_getheroscript()
32152 {
32153 do_get_script_index_by_name(name_to_slot_index_playermap);
32154 }
32155 void FFScript::do_getglobalscript()
32156 {
32157 do_get_script_index_by_name(name_to_slot_index_globalmap);
32158 }
32159 105 void FFScript::do_getdmapscript()
32160 {
32161 105 do_get_script_index_by_name(name_to_slot_index_dmapmap);
32162 105 }
32163 void FFScript::do_getscreenscript()
32164 {
32165 do_get_script_index_by_name(name_to_slot_index_screenmap);
32166 }
32167 31 void FFScript::do_getitemspritescript()
32168 {
32169 31 do_get_script_index_by_name(name_to_slot_index_itemspritemap);
32170 31 }
32171 //Not assigned to slots at present. If they ever are, then this would get the id of any script (any type) by name. -Z
32172 void FFScript::do_getuntypedscript()
32173 {
32174 set_register(sarg1, 0);
32175 }
32176 void FFScript::do_getsubscreenscript()
32177 {
32178 do_get_script_index_by_name(name_to_slot_index_subscreenmap);
32179 }
32180 void FFScript::do_getnpcbyname()
32181 {
32182 int32_t arrayptr = get_register(sarg1);
32183 string the_string;
32184 int32_t num = -1;
32185 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32186
32187 for(int32_t q = 0; q < MAXNPCS; q++)
32188 {
32189 if(!(strcmp(the_string.c_str(), guy_string[q])))
32190 {
32191 num = q;
32192 break;
32193 }
32194 }
32195 set_register(sarg1, (num * 10000));
32196 }
32197 void FFScript::do_getitembyname()
32198 {
32199 int32_t arrayptr = get_register(sarg1);
32200 string the_string;
32201 int32_t num = -1;
32202 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32203
32204 for(int32_t q = 0; q < MAXNPCS; q++)
32205 {
32206 if(!(strcmp(the_string.c_str(), item_string[q])))
32207 {
32208 num = q;
32209 break;
32210 }
32211 }
32212 set_register(sarg1, (num * 10000));
32213 }
32214 void FFScript::do_getcombobyname()
32215 {
32216 int32_t arrayptr = get_register(sarg1);
32217 string the_string;
32218 int32_t num = -1;
32219 ArrayH::getString(arrayptr, the_string, 256);
32220
32221 if (!the_string.empty())
32222 {
32223 for(int32_t q = 0; q < MAXCOMBOS; q++)
32224 {
32225 if (the_string == combobuf[q].label)
32226 {
32227 num = q;
32228 break;
32229 }
32230 }
32231 }
32232 set_register(sarg1, (num * 10000));
32233 }
32234 void FFScript::do_getdmapbyname()
32235 {
32236 int32_t arrayptr = get_register(sarg1);
32237 string the_string;
32238 int32_t num = -1;
32239 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32240
32241 for(int32_t q = 0; q < MAXDMAPS; q++)
32242 {
32243 if(!(strcmp(the_string.c_str(), DMaps[q].name)))
32244 {
32245 num = q;
32246 break;
32247 }
32248 }
32249 set_register(sarg1, (num * 10000));
32250 }
32251
32252 ////////////////////////
32253 /// String Utilities ///
32254 ////////////////////////
32255 void FFScript::do_ConvertCase(const bool v)
32256 {
32257 int32_t arrayptr_a = get_register(sarg1);
32258 string strA;
32259 ArrayH::getString(arrayptr_a, strA);
32260 for (char& c : strA)
32261 {
32262 if (c < 'a')
32263 c += 32 * (c >= 'A' && c <= 'Z');
32264 else
32265 c -= 32 * (c >= 'a' && c <= 'z');
32266 }
32267 ArrayH::setArray(arrayptr_a, strA);
32268 set_register(sarg1, (10000)); // used to return 0 if string was empty.
32269 }
32270
32271 void FFScript::do_xlen(const bool v)
32272 {
32273 //not implemented, xlen not found
32274 int32_t arrayptr = (SH::get_arg(sarg2, v));
32275 string str;
32276 ArrayH::getString(arrayptr, str);
32277 }
32278
32279 void FFScript::do_xtoi(const bool v)
32280 {
32281 int32_t arrayptr = (SH::get_arg(sarg2, v));
32282 string str;
32283 ArrayH::getString(arrayptr, str);
32284 double val = zc_xtoi(const_cast<char*>(str.c_str()));
32285 set_register(sarg1, (int32_t)(val) * 10000);
32286 }
32287 void FFScript::do_xtoi2()
32288 {
32289 int32_t arrayptr_a = ri->d[rINDEX];
32290 string strA;
32291 ArrayH::getString(arrayptr_a, strA);
32292 set_register(sarg1, (zc_xtoi(strA.c_str()) * 10000));
32293 }
32294
32295 // Calculates log2 of number.
32296 double FFScript::Log2( double n )
32297 {
32298 // log(n)/log(2) is log2.
32299 return log( (double)n ) / log( (double)2 );
32300 }
32301
32302 //xtoa, convert hex number to hex ascii
32303 14 void FFScript::do_xtoa()
32304 {
32305
32306 14 int32_t arrayptr_a = get_register(sarg1);
32307 14 int32_t number = get_register(sarg2) / 10000;//ri->d[rEXP2]/10000; //why are you not in sarg2?!!
32308
32309
32310
32311 14 bool isneg = false;
32312
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if ( number < 0 )
32313 {
32314 isneg = true;
32315 number *= -1;
32316 }
32317 14 double num = number;
32318
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 int32_t digits = num ? floor(FFCore.LogToBase(num, 16) + 1) : 1;
32319
32320
32321 14 int32_t pos = 0;
32322 14 string strA;
32323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(number == 0) //Needs to precede str.resize(digits+3) as if the number is <= 0 then this breaks.
32324 {
32325 strA.resize(3);
32326 strA[pos+2] = '0';
32327 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32328 {
32329 Z_scripterrlog("Dest string supplied to 'itoa()' not large enough\n");
32330 set_register(sarg1, 0);
32331 }
32332 else set_register(sarg1, 30000); //returns the pointer to the dest
32333 return;
32334 }
32335 14 int32_t ret = 0;
32336
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA.resize(digits+3+(isneg?1:0));
32337 //num = Floor(Abs(num));
32338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if ( isneg )
32339 {
32340 strA[pos] = '-';
32341 strA[pos+1] = '0';
32342 strA[pos+2] = 'x';
32343 ret = 3;
32344 }
32345 else
32346 {
32347
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos] = '0';
32348
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos+1] = 'x';
32349 14 ret = 2;
32350 }
32351
32352 14 int32_t alphaoffset = 'A' - 0xA;
32353
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 24 times.
38 for(int32_t i = 0; i < digits; ++i)
32354 {
32355
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int32_t coeff = ((int32_t)floor((double)(((double)number) / pow((float)0x10, digits - i - 1))) % 0x10);
32356
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 strA[pos + ret + i] = coeff < 0xA ? coeff + '0' : coeff + alphaoffset;
32357 24 }
32358
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32359 {
32360 scripting_log_error_with_context("Dest string parameter not large enough");
32361 set_register(sarg1, 0);
32362 }
32363
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 else set_register(sarg1, (ret + digits -(isneg?1:0))*10000); //don't count the - sign as a digit
32364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 }
32365
32366 void FFScript::do_ilen(const bool v)
32367 {
32368 int32_t arrayptr = (SH::get_arg(sarg2, v));
32369 string str;
32370 ArrayH::getString(arrayptr, str);
32371 set_register(sarg1, (FFCore.ilen((char*)str.c_str()) * 10000));
32372 }
32373
32374 //! Note atoi2 (atoi(str, len) can be accompished with str.resize after getString.
32375 void FFScript::do_atoi(const bool v)
32376 {
32377 int32_t arrayptr = (SH::get_arg(sarg2, v));
32378 string str;
32379 ArrayH::getString(arrayptr, str);
32380 set_register(sarg1, (atoi(str.c_str()) * 10000));
32381 }
32382 void FFScript::do_atol(const bool v)
32383 {
32384 int32_t arrayptr = (SH::get_arg(sarg2, v));
32385 string str;
32386 ArrayH::getString(arrayptr, str);
32387 set_register(sarg1, (atoi(str.c_str())));
32388 }
32389
32390 void FFScript::do_strstr()
32391 {
32392
32393 int32_t arrayptr_a = ri->d[rINDEX];
32394 int32_t arrayptr_b = ri->d[rINDEX2];
32395 string strA;
32396 string strB;
32397 ArrayH::getString(arrayptr_a, strA);
32398 ArrayH::getString(arrayptr_b, strB);
32399 if ( strA.size() < 1 )
32400 {
32401 scripting_log_error_with_context("String parameter is too small. Size is: {}", strA.size());
32402 set_register(sarg1,-10000);
32403 return;
32404 }
32405 set_register(sarg1, (strA.find(strB) * 10000));
32406 }
32407
32408 935 void FFScript::do_strcat()
32409 {
32410
32411 935 int32_t arrayptr_a = ri->d[rINDEX];
32412 935 int32_t arrayptr_b = ri->d[rINDEX2];
32413 935 string strA;
32414 935 string strB;
32415
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_a, strA);
32416
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_b, strB);
32417 //char str_c[2048];
32418 //strcpy(str_c, strA.c_str());
32419
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 string strC = strA + strB;
32420
2/4
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 935 times.
935 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32421 {
32422 scripting_log_error_with_context("Dest string parameter is too small. Size is: {}", strA.size());
32423 set_register(sarg1, 0);
32424 }
32425
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32426 935 }
32427 void FFScript::do_strspn()
32428 {
32429
32430 int32_t arrayptr_a = ri->d[rINDEX];
32431 int32_t arrayptr_b = ri->d[rINDEX2];
32432 string strA;
32433 string strB;
32434 ArrayH::getString(arrayptr_a, strA);
32435 ArrayH::getString(arrayptr_b, strB);
32436 set_register(sarg1, (strspn(strA.c_str(), strB.c_str()) * 10000));
32437 }
32438
32439 void FFScript::do_strcspn()
32440 {
32441
32442 int32_t arrayptr_a = ri->d[rINDEX];
32443 int32_t arrayptr_b = ri->d[rINDEX2];
32444 string strA;
32445 string strB;
32446 ArrayH::getString(arrayptr_a, strA);
32447 ArrayH::getString(arrayptr_b, strB);
32448 set_register(sarg1, (strcspn(strA.c_str(), strB.c_str()) * 10000));
32449 }
32450
32451 void FFScript::do_strchr()
32452 {
32453
32454 int32_t arrayptr_a = ri->d[rINDEX];
32455 char chr_to_find = (ri->d[rINDEX2]/10000);
32456 string strA;
32457 ArrayH::getString(arrayptr_a, strA);
32458 if ( strA.size() < 1 )
32459 {
32460 scripting_log_error_with_context("String parameter is too small. Size is: {}", strA.size());
32461 set_register(sarg1,-10000);
32462 return;
32463 }
32464
32465 set_register(sarg1,strA.find_first_of(chr_to_find)*10000);
32466 }
32467 void FFScript::do_strrchr()
32468 {
32469 int32_t arrayptr_a = ri->d[rINDEX];
32470 char chr_to_find = (ri->d[rINDEX2]/10000);
32471 string strA;
32472 ArrayH::getString(arrayptr_a, strA);
32473 if ( strA.size() < 1 )
32474 {
32475 scripting_log_error_with_context("String parameter is too small. Size is: {}", strA.size());
32476 set_register(sarg1,-10000);
32477 return;
32478 }
32479 set_register(sarg1,strA.find_last_of(chr_to_find)*10000);
32480 }
32481
32482 void FFScript::do_remchr2()
32483 {
32484 //Not implemented, remchr not found
32485 //not part of any standard library
32486 int32_t arrayptr_a = ri->d[rINDEX];
32487 string strA;
32488 ArrayH::getString(arrayptr_a, strA);
32489 }
32490 //Bookmark
32491 void FFScript::do_atoi2()
32492 {
32493 //not implemented; atoi does not take 2 params
32494 int32_t arrayptr_a = ri->d[rINDEX];
32495 string strA;
32496 ArrayH::getString(arrayptr_a, strA);
32497 }
32498 void FFScript::do_ilen2()
32499 {
32500 //not implemented, ilen not found
32501 int32_t arrayptr_a = ri->d[rINDEX];
32502 string strA;
32503 ArrayH::getString(arrayptr_a, strA);
32504 }
32505 void FFScript::do_xlen2()
32506 {
32507 //not implemented, xlen not found
32508 int32_t arrayptr_a = ri->d[rINDEX];
32509 string strA;
32510 ArrayH::getString(arrayptr_a, strA);
32511 }
32512
32513 4797 void FFScript::do_itoa()
32514 {
32515 4797 int32_t arrayptr_a = get_register(sarg1);
32516 4797 int32_t number = get_register(sarg2) / 10000;
32517
32518 char buf[16];
32519 4797 zc_itoa(number, buf, 10);
32520 4797 int32_t ret = ::strlen(buf) * 10000L;
32521
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 string strA(buf);
32522
32523
2/4
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4797 times.
4797 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32524 {
32525 scripting_log_error_with_context("Dest string parameter is too small. Size is: {}", strA.size());
32526 set_register(sarg1, -1);
32527 }
32528
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 else set_register(sarg1, ret); //returns the number of digits used
32529 4797 }
32530
32531 56 void FFScript::do_itoacat()
32532 {
32533 56 int32_t arrayptr_a = get_register(sarg1);
32534 56 int32_t number = get_register(sarg2) / 10000;
32535
32536 56 double num = number;
32537 56 int32_t digits = FFCore.numDigits(number); //int32_t(log10(temp) * 10000.0)
32538 56 int32_t pos = 0;
32539 56 int32_t ret = 0;
32540 56 string strA;
32541 56 string strB;
32542
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 strB.resize(digits);
32543
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 ArrayH::getString(arrayptr_a, strA);
32544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(num < 0)
32545 {
32546 strB.resize(digits+1);
32547 strB[pos] = '-';
32548 ++ret;
32549 num = -num;
32550 }
32551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 else if(num == 0)
32552 {
32553 strB[pos] = '0';
32554 string strC = strA + strB;
32555 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32556 {
32557 scripting_log_error_with_context("Dest string parameter is too small. Size is: {}", strA.size());
32558 set_register(sarg1, 0);
32559 }
32560 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32561 return;
32562 }
32563
32564
32565
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 84 times.
140 for(int32_t i = 0; i < digits; ++i)
32566
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
84 strB[pos + ret + i] = ((int32_t)floor((double)(num / pow((float)10, digits - i - 1))) % 10) + '0';
32567
32568
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 string strC = strA + strB;
32569
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
56 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32570 {
32571 scripting_log_error_with_context("Dest string parameter is too small. Size is: {}", strA.size());
32572 set_register(sarg1, 0);
32573 }
32574
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 }
32576
32577 2925 void FFScript::do_strcpy(const bool a, const bool b)
32578 {
32579 2925 int32_t arrayptr_b = SH::get_arg(sarg1, a);
32580 2925 int32_t arrayptr_a = SH::get_arg(sarg2, b);
32581
32582 2925 string strA;
32583
32584
1/2
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
2925 ArrayH::getString(arrayptr_a, strA);
32585
32586
2/4
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2925 times.
2925 if(ArrayH::setArray(arrayptr_b, strA) == SH::_Overflow)
32587 scripting_log_error_with_context("Dest string parameter is too small. Size is: {}", strA.size());
32588 2925 }
32589 2 void FFScript::do_arraycpy(const bool a, const bool b)
32590 {
32591 2 int32_t arrayptr_dest = SH::get_arg(sarg1, a);
32592 2 int32_t arrayptr_src = SH::get_arg(sarg2, b);
32593 2 ArrayH::copyValues(arrayptr_dest, arrayptr_src);
32594 2 }
32595 6050 void FFScript::do_strlen(const bool v)
32596 {
32597 6050 int32_t arrayptr = (SH::get_arg(sarg2, v));
32598 6050 string str;
32599
1/2
✓ Branch 0 taken 6050 times.
✗ Branch 1 not taken.
6050 ArrayH::getString(arrayptr, str);
32600
1/2
✓ Branch 0 taken 6050 times.
✗ Branch 1 not taken.
6050 set_register(sarg1, (str.length() * 10000));
32601 6050 }
32602
32603 void FFScript::do_strncmp()
32604 {
32605 int32_t arrayptr_a = ri->d[rINDEX];
32606 int32_t arrayptr_b = ri->d[rEXP2];
32607 int32_t len = ri->d[rEXP1]/10000;
32608 string strA;
32609 string strB;
32610 ArrayH::getString(arrayptr_a, strA);
32611 ArrayH::getString(arrayptr_b, strB);
32612 set_register(sarg1, (strncmp(strA.c_str(), strB.c_str(), len) * 10000));
32613 }
32614
32615 void FFScript::do_strnicmp()
32616 {
32617 int32_t arrayptr_a = ri->d[rINDEX];
32618 int32_t arrayptr_b = ri->d[rEXP2];
32619 int32_t len = ri->d[rEXP1]/10000;
32620 string strA;
32621 string strB;
32622 ArrayH::getString(arrayptr_a, strA);
32623 ArrayH::getString(arrayptr_b, strB);
32624 set_register(sarg1, (ustrnicmp(strA.c_str(), strB.c_str(), len) * 10000));
32625 }
32626
32627 /////////////////////
32628 /// MATHS HELPERS ///
32629 /////////////////////
32630
32631 //Returns the log of val to the base 10. Any value <= 0 will return 0.
32632 int32_t FFScript::Log10(double temp)
32633 {
32634 int32_t ret = 0;
32635 if(temp > 0)
32636 ret = int32_t(log10(temp) * 10000.0);
32637 else ret = 0;
32638 return ret;
32639 }
32640
32641 //Returns the number of digits in a given integer.
32642 56 int32_t FFScript::numDigits(int32_t number)
32643 {
32644 56 int32_t digits = 0;
32645
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 56 times.
140 while (number)
32646 {
32647 84 number /= 10;
32648 84 digits++;
32649 }
32650 56 return digits;
32651 }
32652
32653 // Returns the natural logarithm of val (to the base e). Any value <= 0 will return 0.
32654 28 double FFScript::ln(double temp)
32655 {
32656
32657
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if(temp > 0)
32658 28 return (log(temp));
32659 else
32660 {
32661 return 0;
32662 }
32663 28 }
32664
32665 // Returns the logarithm of x to the given base.
32666 14 double FFScript::LogToBase(double x, double base)
32667 {
32668
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if(x <= 0 || base <= 0) return 0;
32669 14 return FFCore.ln(x)/FFCore.ln(base);
32670 14 }
32671
32672 ///----------------------------------------------------------------------------------------------------//
32673 //Debugger and Logging Consoles
32674
32675 template <typename ...Params>
32676 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
32677 {
32678 //if ( open )
32679 {
32680 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200, NULL, NULL);
32681 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
32682 zscript_coloured_console.gotoxy(0,0);
32683 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32684 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
32685
32686 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)...);
32687 }
32688 //else
32689 //{
32690 //close
32691 // zscript_coloured_console.Close();
32692 //}
32693 }
32694
32695 425 void clearConsole()
32696 {
32697 425 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
32698 425 zscript_coloured_console.gotoxy(0,0);
32699
32700 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32701 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"\n _____ ____ __ \n");
32702 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32703 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /__ / / __ \\__ _____ _____/ /_\n");
32704 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32705 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / / / / / / / / / _ \\/ ___/ __/\n");
32706 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32707 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / /__/ /_/ / /_/ / __(__ ) /_ \n");
32708 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32709 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /____/\\___\\_\\__,_/\\___/____/\\__/\n\n");
32710
32711 425 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32712 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZC Console\n");
32713
32714 850 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32715 425 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Running: %s\n", getVersionString());
32716
2/2
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 111 times.
425 if ( FFCore.getQuestHeaderInfo(vZelda) > 0 )
32717 {
32718 111 char const* verstr = QHeader.getVerStr();
32719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 111 times.
111 if(verstr[0])
32720 {
32721 111 auto vercmp = QHeader.compareVer();
32722 111 auto astatecmp = compare(int32_t(QHeader.getAlphaState()), getAlphaState());
32723 111 auto avercmp = compare(QHeader.getAlphaVer(), 0);
32724 111 auto timecmp = QHeader.compareDate();
32725
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 93 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
111 if(!(vercmp || astatecmp || avercmp))
32726 {
32727
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
18 if(!timecmp || !QHeader.new_version_is_nightly)
32728 36 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32729 18 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in this build\n", verstr);
32730 else if(timecmp < 0)
32731 {
32732 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32733 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an earlier nightly of the same build\n", verstr);
32734 }
32735 else
32736 {
32737 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32738 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an LATER nightly of the same build!\n"
32739 "This may be unsafe to play in this version!\n", verstr);
32740 }
32741 18 }
32742 186 else zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32743 93 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in: %s\n", verstr);
32744 111 }
32745 111 }
32746 425 }
32747 void FFScript::ZScriptConsole(bool open)
32748 {
32749 if ( open )
32750 {
32751 zscript_coloured_console.Create("ZC Console", 600, 200, NULL, NULL);
32752 clearConsole();
32753 console_enabled = 1;
32754 }
32755 else
32756 {
32757 zscript_coloured_console.Close();
32758 console_enabled = 0;
32759 }
32760 zc_set_config("CONSOLE","enabled",console_enabled);
32761 }
32762
32763 ///----------------------------------------------------------------------------------------------------//
32764 //Tracing
32765
32766 12567 void FFScript::do_trace(bool v)
32767 {
32768
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 12567 times.
✓ Branch 2 taken 12567 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12567 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12567 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 12567 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
25134 bool should_replay_trace = replay_is_active() && replay_get_meta_bool("script_trace");
32769 // For now, only prevent tracing to allegro log for Web version. Some quests may expect players to
32770 // look in the logs for spoiler/secret stuff.
32771 #ifdef __EMSCRIPTEN__
32772 bool should_trace = console_enabled || should_replay_trace;
32773 if (!should_trace) return;
32774 #endif
32775
32776 12567 int32_t temp = SH::get_arg(sarg1, v);
32777
32778 char tmp[100];
32779
2/2
✓ Branch 0 taken 12561 times.
✓ Branch 1 taken 6 times.
12567 sprintf(tmp, (temp < 0 ? "%06d" : "%05d"), temp);
32780
1/2
✓ Branch 0 taken 12567 times.
✗ Branch 1 not taken.
12567 string s2(tmp);
32781
5/10
✓ Branch 0 taken 12567 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12567 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12567 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12567 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12567 times.
✗ Branch 9 not taken.
12567 s2 = s2.substr(0, s2.size() - 4) + "." + s2.substr(s2.size() - 4, 4) + "\n";
32782
1/2
✓ Branch 0 taken 12567 times.
✗ Branch 1 not taken.
12567 TraceScriptIDs();
32783
1/2
✓ Branch 0 taken 12567 times.
✗ Branch 1 not taken.
12567 al_trace("%s", s2.c_str());
32784
2/2
✓ Branch 0 taken 2290 times.
✓ Branch 1 taken 10277 times.
12567 if (should_replay_trace)
32785
2/4
✓ Branch 0 taken 2290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2290 times.
✗ Branch 3 not taken.
2290 replay_step_comment("trace: " + s2);
32786
32787
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12567 times.
12567 if ( console_enabled )
32788 {
32789 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32790 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
32791 }
32792 12567 }
32793 void FFScript::do_tracel(bool v)
32794 {
32795 int32_t temp = SH::get_arg(sarg1, v);
32796
32797 char tmp[32];
32798 sprintf(tmp, "%d\n", temp);
32799 TraceScriptIDs();
32800 al_trace("%s", tmp);
32801 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32802 replay_step_comment(fmt::format("trace: {}", temp));
32803
32804 if ( console_enabled )
32805 {
32806 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32807 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),tmp);
32808 }
32809 }
32810
32811 void FFScript::do_tracebool(const bool v)
32812 {
32813 int32_t temp = SH::get_arg(sarg1, v);
32814 TraceScriptIDs();
32815 char const* str = temp ? "true\n" : "false\n";
32816 al_trace("%s", str);
32817 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32818 replay_step_comment(fmt::format("trace: {}", (bool)temp));
32819
32820 if ( console_enabled )
32821 {
32822 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32823 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str);
32824 }
32825 }
32826
32827 35258 void traceStr(string const& str)
32828 {
32829 35258 FFCore.TraceScriptIDs();
32830 35258 safe_al_trace(str);
32831
7/16
✗ Branch 0 not taken.
✓ Branch 1 taken 35258 times.
✓ Branch 2 taken 35258 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35258 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 35258 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 35258 times.
✓ Branch 10 taken 1642 times.
✓ Branch 11 taken 33616 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
70516 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32832
1/2
✓ Branch 0 taken 33616 times.
✗ Branch 1 not taken.
33616 replay_step_comment("trace: " + str);
32833
32834
1/2
✓ Branch 0 taken 35258 times.
✗ Branch 1 not taken.
35258 if ( console_enabled )
32835 {
32836 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32837 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str.c_str());
32838 }
32839 35258 }
32840
32841 1383 void FFScript::do_tracestring()
32842 {
32843 1383 int32_t arrayptr = get_register(sarg1);
32844 1383 string str;
32845
1/2
✓ Branch 0 taken 1383 times.
✗ Branch 1 not taken.
1383 ArrayH::getString(arrayptr, str, 512);
32846
1/2
✓ Branch 0 taken 1383 times.
✗ Branch 1 not taken.
1383 str += "\0"; //In the event that the user passed an array w/o NULL, don't crash.
32847
1/2
✓ Branch 0 taken 1383 times.
✗ Branch 1 not taken.
1383 traceStr(str);
32848 1383 }
32849
32850 bool is_valid_format(char c)
32851 {
32852 switch(c)
32853 {
32854 case 'f': case 'd': case 'i': case 'p':
32855 case 'l': case 's': case 'c': case 'X':
32856 case 'x': case 'b': case 'B': case 'a':
32857 return true;
32858 }
32859 return false;
32860 }
32861 #define FORMATTER_FLAG_0FILL 0x01
32862 88455 char const* zs_formatter(char const* format, int32_t arg, int32_t mindig, dword flags)
32863 {
32864
3/4
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 88400 times.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
88455 static std::string ret;
32865
32866 88455 ret.clear();
32867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88455 times.
88455 if(format)
32868 {
32869 176910 std::string mdstr = fmt::format("%{}{}{}",(flags&FORMATTER_FLAG_0FILL)?"0":"",
32870
2/4
✓ Branch 0 taken 88455 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 88455 times.
88455 mindig, (format[0] == 'x' || format[0] == 'X') ? format[0] : 'd');
32871 88455 char const* mindigbuf = mdstr.c_str();
32872 88455 bool tempbool = false;
32873
3/12
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 79528 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 8375 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
88455 switch(format[0])
32874 {
32875 case 'f':
32876 tempbool = true;
32877 [[fallthrough]];
32878 case 'd':
32879
2/2
✓ Branch 0 taken 78585 times.
✓ Branch 1 taken 943 times.
80471 if(arg%10000)
32880 943 tempbool = true;
32881 [[fallthrough]];
32882 case 'i':
32883 case 'p':
32884 {
32885 79528 char argbuf[32] = {0};
32886 79528 bool neg = arg < 0;
32887
2/2
✓ Branch 0 taken 78111 times.
✓ Branch 1 taken 1417 times.
79528 if(mindig)
32888 1417 sprintf(argbuf,mindigbuf,arg / 10000);
32889
1/2
✓ Branch 0 taken 78111 times.
✗ Branch 1 not taken.
78111 else zc_itoa(arg / 10000, argbuf);
32890
32891
2/2
✓ Branch 0 taken 78585 times.
✓ Branch 1 taken 943 times.
79528 if(tempbool) //add decimal places
32892 {
32893 943 arg = abs(arg);
32894 943 auto ind = strlen(argbuf);
32895 943 argbuf[ind++] = '.';
32896
2/2
✓ Branch 0 taken 3772 times.
✓ Branch 1 taken 943 times.
4715 for(int div = 1000; div > 0; div /= 10)
32897 3772 argbuf[ind++] = '0' + (arg/div)%10;
32898
4/4
✓ Branch 0 taken 943 times.
✓ Branch 1 taken 488 times.
✓ Branch 2 taken 488 times.
✓ Branch 3 taken 943 times.
1431 for(--ind; argbuf[ind]=='0' && argbuf[ind-1]!='-'; --ind)
32899 {
32900 488 argbuf[ind] = 0;
32901 488 }
32902 943 }
32903
32904
4/4
✓ Branch 0 taken 10938 times.
✓ Branch 1 taken 68590 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 10834 times.
79528 if(neg && argbuf[0] != '-')
32905
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 ret = "-";
32906
1/2
✓ Branch 0 taken 79528 times.
✗ Branch 1 not taken.
79528 ret += argbuf;
32907 79528 return ret.c_str();
32908 }
32909 //
32910 case 'l':
32911 {
32912 char argbuf[32] = {0};
32913 if(mindig)
32914 sprintf(argbuf, mindigbuf, arg);
32915 else zc_itoa(arg, argbuf);
32916
32917 ret = argbuf;
32918 return ret.c_str();
32919 }
32920 //
32921 case 's':
32922 {
32923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8375 times.
8375 if(mindig)
32924 Z_scripterrlog("Cannot use minimum digits flag for '%%s'\n");
32925
1/2
✓ Branch 0 taken 8375 times.
✗ Branch 1 not taken.
8375 if(arg)
32926 {
32927 8375 int32_t strptr = arg;
32928
1/2
✓ Branch 0 taken 8375 times.
✗ Branch 1 not taken.
8375 ArrayManager am(strptr);
32929
2/4
✓ Branch 0 taken 8375 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8375 times.
8375 if(am.invalid())
32930 ret = "<INVALID STRING>";
32931
1/2
✓ Branch 0 taken 8375 times.
✗ Branch 1 not taken.
8375 else ArrayH::getString(strptr, ret, MAX_ZC_ARRAY_SIZE);
32932 8375 }
32933 else ret = "<NULL>";
32934 8375 return ret.c_str();
32935 }
32936 case 'c':
32937 {
32938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if(mindig)
32939 Z_scripterrlog("Cannot use minimum digits flag for '%%c'\n");
32940 552 int32_t c = (arg / 10000);
32941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if ( (byte(c)) != c )
32942 {
32943 Z_scripterrlog("Illegal char value (%d) passed to sprintf as '%%c' arg\n", c);
32944 Z_scripterrlog("Value of invalid char will overflow.\n");
32945 }
32946
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 ret.push_back(byte(c));
32947 552 return ret.c_str();
32948 }
32949 //
32950 case 'X':
32951 tempbool = true;
32952 [[fallthrough]];
32953 case 'x':
32954 {
32955 char argbuf[32] = {0};
32956 if(mindig)
32957 sprintf(argbuf,mindigbuf,arg / 10000);
32958 else zc_itoa( (arg/10000), argbuf, 16 ); //base 16; hex
32959
32960 for ( int32_t inx = 0; inx < 16; ++inx ) //set chosen caps
32961 {
32962 argbuf[inx] = ( tempbool ? toupper(argbuf[inx]) : tolower(argbuf[inx]) );
32963 }
32964 ret = "0x";
32965 ret += argbuf;
32966 return ret.c_str();
32967 }
32968 //
32969 case 'b': //int binary
32970 arg /= 10000;
32971 [[fallthrough]];
32972 case 'B': //long binary
32973 {
32974 char argbuf[33] = {0};
32975 int num_digits = mindig;
32976 for(int q = num_digits; q < 32; ++q)
32977 if(arg&(1<<q))
32978 num_digits = q+1;
32979 for(int q = 0; q < num_digits; ++q)
32980 {
32981 argbuf[q] = (arg&(1<<(num_digits-q-1)))
32982 ? '1' : '0';
32983 }
32984 ret = argbuf;
32985 return ret.c_str();
32986 }
32987 case 'a': //array
32988 {
32989 if(arg)
32990 {
32991 if(!is_valid_format(format[1]))
32992 {
32993 Z_scripterrlog("Format '%%a%c' is invalid!\n",format[1]);
32994 break;
32995 }
32996 ArrayManager am(arg);
32997 ret = am.asString([&](int32_t val)
32998 {
32999 return zs_formatter(format+1, val, mindig, flags);
33000 }, 214748);
33001 }
33002 else ret = "{ NULL }";
33003 return ret.c_str();
33004 }
33005 default:
33006 {
33007 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
33008 return ret.c_str();
33009 }
33010 }
33011
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 88455 times.
✗ Branch 2 not taken.
88455 }
33012 Z_scripterrlog("Error: No format parameter given for zs_formatter\n");
33013 return ret.c_str();
33014 88455 }
33015
33016 64907 static int32_t zspr_varg_getter(int32_t,int32_t next_arg)
33017 {
33018 64907 return zs_vargs.at(next_arg);
33019 }
33020 23548 static int32_t zspr_stack_getter(int32_t num_args, int32_t next_arg)
33021 {
33022 23548 return SH::read_stack(((ri->sp + num_args) - 1) - next_arg);
33023 }
33024 45839 string zs_sprintf(char const* format, int32_t num_args, std::function<int32_t(int32_t,int32_t)> arg_getter)
33025 {
33026 45839 int32_t next_arg = 0;
33027 45839 bool is_old_args = get_qr(qr_OLD_PRINTF_ARGS);
33028 45839 ostringstream oss;
33029
2/2
✓ Branch 0 taken 12079 times.
✓ Branch 1 taken 122215 times.
134294 while(format[0] != '\0')
33030 {
33031 122215 int32_t arg_val = 0;
33032
2/2
✓ Branch 0 taken 88455 times.
✓ Branch 1 taken 33760 times.
122215 if(next_arg < num_args)
33033 {
33034
1/2
✓ Branch 0 taken 88455 times.
✗ Branch 1 not taken.
88455 arg_val = arg_getter(num_args,next_arg);
33035 88455 }
33036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33760 times.
33760 else if(get_qr(qr_PRINTF_NO_0FILL))
33037 {
33038 oss << format;
33039 return oss.str();
33040 }
33041 122215 char buf[256] = {0};
33042
2/2
✓ Branch 0 taken 88455 times.
✓ Branch 1 taken 461245 times.
549700 for ( int32_t q = 0; q < 256; ++q )
33043 {
33044
2/2
✓ Branch 0 taken 33760 times.
✓ Branch 1 taken 427485 times.
461245 if(format[0] == '\0') //done
33045 {
33046
1/2
✓ Branch 0 taken 33760 times.
✗ Branch 1 not taken.
33760 oss << buf;
33047
1/2
✓ Branch 0 taken 33760 times.
✗ Branch 1 not taken.
33760 return oss.str();
33048 }
33049
2/2
✓ Branch 0 taken 89085 times.
✓ Branch 1 taken 338400 times.
427485 else if(format[0] == '%')
33050 {
33051 89085 ++format;
33052 89085 int32_t min_digits = 0;
33053 89085 dword formatter_flags = 0;
33054
5/6
✓ Branch 0 taken 88455 times.
✓ Branch 1 taken 630 times.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 87038 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1417 times.
89085 if(format[0] >= '0' && format[0] <= '9' && !is_old_args)
33055 {
33056 1417 char argbuf[4] = {0};
33057 1417 int32_t q = 0;
33058
1/2
✓ Branch 0 taken 1417 times.
✗ Branch 1 not taken.
1417 if(format[0] == '0') //Leading 0 means to 0-fill, and gets eaten
33059 1417 formatter_flags |= FORMATTER_FLAG_0FILL;
33060 else --format; //else don't eat
33061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 while(q < 4)
33062 {
33063 2834 ++format;
33064 2834 char c = format[0];
33065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 if(c == '\0')
33066 {
33067 Z_scripterrlog("Cannot use minimum digits flag with no argument\n");
33068 oss << buf;
33069 return oss.str();
33070 }
33071
3/4
✓ Branch 0 taken 2834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 1417 times.
2834 if(c >= '0' && c <= '9')
33072 1417 argbuf[q++] = c;
33073 else
33074 {
33075 1417 --format;
33076 1417 break;
33077 }
33078 }
33079 1417 ++format;
33080 1417 min_digits = atoi(argbuf);
33081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1417 times.
1417 if(!min_digits)
33082 {
33083 Z_scripterrlog("Error formatting string: Invalid number '%s'\n", argbuf);
33084 }
33085 1417 }
33086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89085 times.
89085 bool bin = (format[0] == 'b' || format[0] == 'B');
33087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89085 times.
89085 bool hex = (format[0] == 'x' || format[0] == 'X');
33088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89085 times.
89085 if(bin)
33089 {
33090 if(min_digits > 32)
33091 {
33092 Z_scripterrlog("Min digits argument cannot be larger than 32!"
33093 " Value will be truncated to 32.");
33094 min_digits = 32;
33095 }
33096 }
33097
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89085 times.
89085 else if(min_digits > 10)
33098 {
33099 Z_scripterrlog("Min digits argument cannot be larger than 10!"
33100 " Value will be truncated to 10.");
33101 min_digits = 10;
33102 }
33103
33104 89085 bool tempbool = false;
33105
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 88455 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 630 times.
89085 switch( format[0] )
33106 {
33107 case 'd':
33108 case 'f':
33109 case 'i': case 'p':
33110 case 'l':
33111 case 's':
33112 case 'c':
33113 case 'x': case 'X':
33114 case 'b': case 'B':
33115 {
33116 88455 ++next_arg;
33117
3/6
✓ Branch 0 taken 88455 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88455 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88455 times.
✗ Branch 5 not taken.
88455 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
33118 88455 q = 300; //break main loop
33119 88455 break;
33120 }
33121 case 'a': //array print
33122 {
33123 ++next_arg;
33124 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
33125 while(format[0] == 'a')
33126 {
33127 if(is_valid_format(format[1]))
33128 ++format;
33129 else break;
33130 }
33131 q = 300; //break main loop
33132 break;
33133 }
33134 case '%':
33135 {
33136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 630 times.
630 if(min_digits)
33137 Z_scripterrlog("Cannot use minimum digits flag for '%%%%'\n");
33138 630 buf[q] = '%';
33139 630 break;
33140 }
33141 default:
33142 {
33143 if(is_old_args)
33144 buf[q] = format[0];
33145 else
33146 {
33147 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
33148 }
33149 break;
33150 }
33151 }
33152 89085 ++format;
33153 89085 }
33154 else
33155 {
33156 338400 buf[q] = format[0];
33157 338400 ++format;
33158 }
33159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 427485 times.
427485 if(q == 255)
33160 {
33161 oss << buf;
33162 break;
33163 }
33164 427485 }
33165 }
33166
1/2
✓ Branch 0 taken 12079 times.
✗ Branch 1 not taken.
12079 return oss.str();
33167 45839 }
33168
33169 33875 void FFScript::do_printf(const bool v, const bool varg)
33170 {
33171 int32_t num_args, format_arrayptr;
33172
2/2
✓ Branch 0 taken 33588 times.
✓ Branch 1 taken 287 times.
33875 if(varg)
33173 {
33174 33588 num_args = zs_vargs.size();
33175 33588 format_arrayptr = SH::read_stack(ri->sp);
33176 33588 }
33177 else
33178 {
33179 287 num_args = SH::get_arg(sarg1, v) / 10000;
33180 287 format_arrayptr = SH::read_stack(ri->sp + num_args);
33181 }
33182 33875 ArrayManager fmt_am(format_arrayptr);
33183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33875 times.
33875 if(!fmt_am.invalid())
33184 {
33185 33875 string formatstr;
33186
1/2
✓ Branch 0 taken 33875 times.
✗ Branch 1 not taken.
33875 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33187
33188
4/6
✓ Branch 0 taken 33588 times.
✓ Branch 1 taken 287 times.
✓ Branch 2 taken 33875 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 33875 times.
33875 traceStr(zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter));
33189 33875 }
33190
2/2
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 33588 times.
33875 if(varg)
33191 33588 zs_vargs.clear();
33192 33875 }
33193 11964 void FFScript::do_sprintf(const bool v, const bool varg)
33194 {
33195 int32_t num_args, dest_arrayptr, format_arrayptr;
33196
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
11964 if(varg)
33197 {
33198 319 num_args = zs_vargs.size();
33199 319 dest_arrayptr = SH::read_stack(ri->sp + 1);
33200 319 format_arrayptr = SH::read_stack(ri->sp);
33201 319 }
33202 else
33203 {
33204 11645 num_args = SH::get_arg(sarg1, v) / 10000;
33205 11645 dest_arrayptr = SH::read_stack(ri->sp + num_args + 1);
33206 11645 format_arrayptr = SH::read_stack(ri->sp + num_args);
33207 }
33208 11964 ArrayManager fmt_am(format_arrayptr);
33209 11964 ArrayManager dst_am(dest_arrayptr);
33210
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(fmt_am.invalid() || dst_am.invalid())
33211 ri->d[rEXP1] = 0;
33212 else
33213 {
33214 11964 string formatstr;
33215
1/2
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
11964 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33216
33217
3/4
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 string output = zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter);
33218
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
33219 {
33220 Z_scripterrlog("Dest string supplied to 'sprintf()' not large enough and cannot be resized\n");
33221 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
33222 }
33223 11964 else ri->d[rEXP1] = output.size();
33224 11964 }
33225
2/2
✓ Branch 0 taken 11645 times.
✓ Branch 1 taken 319 times.
11964 if(varg)
33226 319 zs_vargs.clear();
33227 11964 }
33228 void FFScript::do_printfarr()
33229 {
33230 int32_t format_arrayptr = SH::read_stack(ri->sp + 1),
33231 args_arrayptr = SH::read_stack(ri->sp + 0);
33232 ArrayManager fmt_am(format_arrayptr);
33233 ArrayManager arg_am(args_arrayptr);
33234 if(!(fmt_am.invalid() || arg_am.invalid()))
33235 {
33236 auto num_args = arg_am.size();
33237 string formatstr;
33238 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33239
33240 traceStr(zs_sprintf(formatstr.c_str(), num_args,
33241 [&](int32_t,int32_t next_arg)
33242 {
33243 return arg_am.get(next_arg);
33244 }));
33245 }
33246 }
33247 void FFScript::do_sprintfarr()
33248 {
33249 int32_t dest_arrayptr = SH::read_stack(ri->sp + 2),
33250 format_arrayptr = SH::read_stack(ri->sp + 1),
33251 args_arrayptr = SH::read_stack(ri->sp + 0);
33252 ArrayManager fmt_am(format_arrayptr);
33253 ArrayManager arg_am(args_arrayptr);
33254 ArrayManager dst_am(dest_arrayptr);
33255 if(fmt_am.invalid() || arg_am.invalid() || dst_am.invalid())
33256 ri->d[rEXP1] = 0;
33257 else
33258 {
33259 auto num_args = arg_am.size();
33260 string formatstr;
33261 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33262
33263 string output = zs_sprintf(formatstr.c_str(), num_args,
33264 [&](int32_t,int32_t next_arg)
33265 {
33266 return arg_am.get(next_arg);
33267 });
33268
33269 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
33270 {
33271 Z_scripterrlog("Dest string supplied to 'sprintfa()' not large enough and cannot be resized\n");
33272 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
33273 }
33274 else ri->d[rEXP1] = output.size();
33275 }
33276 }
33277 1520226 void FFScript::do_varg_max()
33278 {
33279 1520226 int32_t num_args = zs_vargs.size();
33280 1520226 int32_t val = 0;
33281
1/2
✓ Branch 0 taken 1520226 times.
✗ Branch 1 not taken.
1520226 if (num_args > 0)
33282 1520226 val = zs_vargs.at(0);
33283
2/2
✓ Branch 0 taken 1520226 times.
✓ Branch 1 taken 1520226 times.
3040452 for(auto q = 1; q < num_args; ++q)
33284 {
33285 1520226 int32_t tval = zs_vargs.at(q);
33286
2/2
✓ Branch 0 taken 1232999 times.
✓ Branch 1 taken 287227 times.
1520226 if(tval > val) val = tval;
33287 1520226 }
33288 1520226 zs_vargs.clear();
33289 1520226 ri->d[rEXP1] = val;
33290 1520226 }
33291 140585 void FFScript::do_varg_min()
33292 {
33293 140585 int32_t num_args = zs_vargs.size();
33294 140585 int32_t val = 0;
33295
1/2
✓ Branch 0 taken 140585 times.
✗ Branch 1 not taken.
140585 if (num_args > 0)
33296 140585 val = zs_vargs.at(0);
33297
2/2
✓ Branch 0 taken 140585 times.
✓ Branch 1 taken 143259 times.
283844 for(auto q = 1; q < num_args; ++q)
33298 {
33299 143259 int32_t tval = zs_vargs.at(q);
33300
2/2
✓ Branch 0 taken 110088 times.
✓ Branch 1 taken 33171 times.
143259 if(tval < val) val = tval;
33301 143259 }
33302 140585 zs_vargs.clear();
33303 140585 ri->d[rEXP1] = val;
33304 140585 }
33305 5 void FFScript::do_varg_choose()
33306 {
33307 5 int32_t num_args = zs_vargs.size();
33308 5 int32_t val = 0;
33309
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(num_args > 0)
33310 {
33311 5 int32_t choice = zc_rand(num_args-1);
33312 5 val = zs_vargs.at(choice);
33313 5 }
33314 5 zs_vargs.clear();
33315 5 ri->d[rEXP1] = val;
33316 5 }
33317 30 void FFScript::do_varg_makearray(ScriptType type, const uint32_t UID, script_object_type object_type)
33318 {
33319 30 auto vargs = zs_vargs;
33320 30 zs_vargs.clear();
33321
33322 30 size_t size = vargs.size();
33323 30 ri->d[rEXP1] = 0;
33324
33325
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 if (ZScriptVersion::gc_arrays())
33326 {
33327
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 auto* array = script_arrays.create();
33328
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (!array)
33329 return;
33330
33331 30 ZScriptArray &a = array->arr;
33332
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.Resize(size);
33333
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.setValid(true);
33334
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.setObjectType(object_type);
33335
33336
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 30 times.
76 for(size_t j = 0; j < size; ++j)
33337
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 a[j] = vargs[j]; //initialize array
33338
33339 30 ri->d[rEXP1] = array->id;
33340
33341 30 return;
33342 }
33343
33344 dword ptrval;
33345 for(ptrval = 1; localRAM[ptrval].Valid(); ptrval++) ;
33346
33347 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
33348 {
33349 Z_scripterrlog("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
33350 ptrval = 0;
33351 }
33352 else
33353 {
33354 ZScriptArray &a = localRAM[ptrval];
33355
33356 a.Resize(size);
33357 a.setValid(true);
33358
33359 for(size_t j = 0; j < size; ++j)
33360 a[j] = vargs[j]; //initialize array
33361
33362 arrayOwner[ptrval].clear();
33363 arrayOwner[ptrval].reown(type, UID);
33364 }
33365
33366 ri->d[rEXP1] = ptrval*10000;
33367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 }
33368
33369 void FFScript::do_breakpoint()
33370 {
33371 // TODO: implement as `debugger;` statement when VS Code extension exists.
33372 }
33373
33374 22 void FFScript::do_tracenl()
33375 {
33376 22 safe_al_trace("\n");
33377
33378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if ( console_enabled )
33379 {
33380 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
33381 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),"\n");
33382 }
33383 22 }
33384
33385
33386 211829 void FFScript::TraceScriptIDs(bool force_show_context)
33387 {
33388 if(DEVTIMESTAMP)
33389 {
33390 CConsoleLoggerEx console = zscript_coloured_console;
33391 bool cond = console_enabled;
33392
33393 char buf[256] = {0};
33394 //Calculate timestamp
33395 struct tm * tm_struct;
33396 time_t sysRTC;
33397 time (&sysRTC);
33398 tm_struct = localtime (&sysRTC);
33399
33400 sprintf(buf, "[%d:%d:%d] ", tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec);
33401 //
33402
33403 al_trace("%s", buf);
33404 if ( cond ) {console.safeprint((CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
33405 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf); }
33406 }
33407
33408
4/4
✓ Branch 0 taken 164001 times.
✓ Branch 1 taken 47828 times.
✓ Branch 2 taken 42645 times.
✓ Branch 3 taken 5183 times.
211829 bool show_context = force_show_context || (get_qr(qr_TRACESCRIPTIDS) || DEVLOGGING);
33409
2/2
✓ Branch 0 taken 5183 times.
✓ Branch 1 taken 206646 times.
211829 if (show_context)
33410 {
33411 206646 CConsoleLoggerEx console = zscript_coloured_console;
33412 206646 bool cond = console_enabled;
33413 206646 char buf[256] = {0};
33414
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 206640 times.
206646 if(script_funcrun)
33415 {
33416
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 sprintf(buf, "Destructor(%d,%s): ", ri->thiskey, destructstr?destructstr->c_str():"UNKNOWN");
33417 6 }
33418
9/18
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 157107 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 30698 times.
✓ Branch 9 taken 53 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 94 times.
✓ Branch 12 taken 3920 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 14708 times.
✗ Branch 17 not taken.
206640 else switch(curScriptType)
33419 {
33420 case ScriptType::Global:
33421 {
33422
2/9
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14680 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
14708 switch(curScriptNum)
33423 {
33424 case GLOBAL_SCRIPT_INIT:
33425
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 sprintf(buf, "Global Init(%s): ", globalmap[curScriptNum].scriptname.c_str());
33426 28 break;
33427 case GLOBAL_SCRIPT_GAME:
33428
1/2
✓ Branch 0 taken 14680 times.
✗ Branch 1 not taken.
14680 sprintf(buf, "Global Active(%s): ", globalmap[curScriptNum].scriptname.c_str());
33429 14680 break;
33430 case GLOBAL_SCRIPT_END:
33431 sprintf(buf, "Global Exit(%s): ", globalmap[curScriptNum].scriptname.c_str());
33432 break;
33433 case GLOBAL_SCRIPT_ONSAVELOAD:
33434 sprintf(buf, "Global SaveLoad(%s): ", globalmap[curScriptNum].scriptname.c_str());
33435 break;
33436 case GLOBAL_SCRIPT_ONLAUNCH:
33437 sprintf(buf, "Global Launch(%s): ", globalmap[curScriptNum].scriptname.c_str());
33438 break;
33439 case GLOBAL_SCRIPT_ONCONTGAME:
33440 sprintf(buf, "Global ContGame(%s): ", globalmap[curScriptNum].scriptname.c_str());
33441 break;
33442 case GLOBAL_SCRIPT_F6:
33443 sprintf(buf, "Global F6Menu(%s): ", globalmap[curScriptNum].scriptname.c_str());
33444 break;
33445 case GLOBAL_SCRIPT_ONSAVE:
33446 sprintf(buf, "Global Save(%s): ", globalmap[curScriptNum].scriptname.c_str());
33447 break;
33448 }
33449 14708 break;
33450 }
33451
33452 case ScriptType::Hero:
33453 {
33454 switch(curScriptNum)
33455 {
33456 case SCRIPT_HERO_INIT:
33457 sprintf(buf, "Hero Init(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33458 break;
33459 case SCRIPT_HERO_ACTIVE:
33460 sprintf(buf, "Hero Active(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33461 break;
33462 case SCRIPT_HERO_DEATH:
33463 sprintf(buf, "Hero Death(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33464 break;
33465 case SCRIPT_HERO_WIN:
33466 sprintf(buf, "Hero Win(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33467 break;
33468 }
33469 break;
33470 }
33471
33472 case ScriptType::Lwpn:
33473
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 sprintf(buf, "LWeapon(%u, %s): ", curScriptNum,lwpnmap[curScriptNum-1].scriptname.c_str());
33474 48 break;
33475
33476 case ScriptType::Ewpn:
33477 sprintf(buf, "EWeapon(%u, %s): ", curScriptNum,ewpnmap[curScriptNum-1].scriptname.c_str());
33478 break;
33479
33480 case ScriptType::NPC:
33481 sprintf(buf, "NPC(%u, %s): ", curScriptNum,npcmap[curScriptNum-1].scriptname.c_str());
33482 break;
33483
33484 case ScriptType::FFC:
33485
1/2
✓ Branch 0 taken 157107 times.
✗ Branch 1 not taken.
157107 sprintf(buf, "FFC(%u, %s): ", curScriptNum,ffcmap[curScriptNum-1].scriptname.c_str());
33486 157107 break;
33487
33488 case ScriptType::Item:
33489 sprintf(buf, "Item(%u, %s): ", curScriptNum,itemmap[curScriptNum-1].scriptname.c_str());
33490 break;
33491
33492 case ScriptType::OnMap:
33493 sprintf(buf, "DMapMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33494 break;
33495 case ScriptType::ScriptedActiveSubscreen:
33496 sprintf(buf, "DMapASub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33497 break;
33498 case ScriptType::ScriptedPassiveSubscreen:
33499
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sprintf(buf, "DMapPSub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33500 2 break;
33501 case ScriptType::DMap:
33502
1/2
✓ Branch 0 taken 30698 times.
✗ Branch 1 not taken.
30698 sprintf(buf, "DMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33503 30698 break;
33504
33505 case ScriptType::ItemSprite:
33506
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 sprintf(buf, "ItemSprite(%u, %s): ", curScriptNum,itemspritemap[curScriptNum-1].scriptname.c_str());
33507 53 break;
33508
33509 case ScriptType::Screen:
33510
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sprintf(buf, "Screen(%u, %s): ", curScriptNum,screenmap[curScriptNum-1].scriptname.c_str());
33511 10 break;
33512
33513 case ScriptType::Combo:
33514
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 sprintf(buf, "Combo(%u, %s): ", curScriptNum,comboscriptmap[curScriptNum-1].scriptname.c_str());
33515 94 break;
33516
33517 case ScriptType::Generic:
33518
1/2
✓ Branch 0 taken 3920 times.
✗ Branch 1 not taken.
3920 sprintf(buf, "Generic(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
33519 3920 break;
33520
33521 case ScriptType::GenericFrozen:
33522 sprintf(buf, "GenericFRZ(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
33523 break;
33524
33525 case ScriptType::EngineSubscreen:
33526 sprintf(buf, "Subscreen(%u, %s): ", curScriptNum,subscreenmap[curScriptNum-1].scriptname.c_str());
33527 break;
33528 }
33529
33530
1/2
✓ Branch 0 taken 206646 times.
✗ Branch 1 not taken.
206646 al_trace("%s", buf);
33531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206646 times.
206646 if ( cond )
33532 console.safeprint((CConsoleLoggerEx::COLOR_GREEN|CConsoleLoggerEx::COLOR_INTENSITY|
33533 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf);
33534 206646 }
33535 211829 }
33536
33537 2 void FFScript::do_cleartrace()
33538 {
33539 2 zc_trace_clear();
33540 2 clearConsole();
33541 2 }
33542
33543 3 string inttobase(word base, int32_t x, word mindigits)
33544 {
33545 static const char coeff[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
33546
33547 3 string s2;
33548
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 word digits = zc_max(mindigits - 1, word(floor(log(double(x)) / log(double(base)))));
33549
33550
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 for(int32_t i = digits; i >= 0; i--)
33551 {
33552
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 s2 += coeff[word(floor(x / pow(double(base), i))) % base];
33553 11 }
33554
33555 3 return s2;
33556
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 }
33557
33558 3 void FFScript::do_tracetobase()
33559 {
33560 3 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
33561 3 uint32_t base = vbound(SH::read_stack(ri->sp + 1) / 10000, 2, 36);
33562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 uint32_t mindigits = zc_max(1, SH::read_stack(ri->sp) / 10000);
33563
33564
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 string s2 = x < 0 ? "-": "";
33565
33566
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 switch(base)
33567 {
33568 case 8:
33569 s2 += '0';
33570 break;
33571
33572 case 16:
33573 s2 += "0x";
33574 break;
33575 }
33576
33577
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 s2 += inttobase(base, int32_t(fabs(double(x))), mindigits);
33578
33579
2/3
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
3 switch(base)
33580 {
33581 case 8:
33582 case 10:
33583 case 16:
33584 2 break;
33585
33586 case 2:
33587
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 s2 += 'b';
33588 1 break;
33589
33590 default:
33591 std::stringstream ss;
33592 ss << " (Base " << base << ')';
33593 s2 += ss.str();
33594 break;
33595 }
33596
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TraceScriptIDs();
33597
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 s2 += "\n";
33598
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 al_trace("%s", s2.c_str());
33599
33600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( console_enabled )
33601 {
33602 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
33603 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
33604 }
33605 3 }
33606
33607 //SRAM Functions
33608 void FFScript::write_dmaps(PACKFILE *f, int32_t vers_id)
33609 {
33610 word dmap_count=count_dmaps();
33611
33612 dmap_count=zc_min(dmap_count, 512);
33613 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
33614
33615 //finally... section data
33616 if(!p_iputw(dmap_count,f))
33617 {
33618 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
33619 }
33620
33621
33622 for(int32_t i=0; i<dmap_count; i++)
33623 {
33624 if(!p_putc(DMaps[i].map,f))
33625 {
33626 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
33627 }
33628
33629 if(!p_iputw(DMaps[i].level,f))
33630 {
33631 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
33632 }
33633
33634 if(!p_putc(DMaps[i].xoff,f))
33635 {
33636 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
33637 }
33638
33639 if(!p_putc(DMaps[i].compass,f))
33640 {
33641 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
33642 }
33643
33644 if(!p_iputw(DMaps[i].color,f))
33645 {
33646 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
33647 }
33648
33649 if(!p_putc(DMaps[i].midi,f))
33650 {
33651 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
33652 }
33653
33654 if(!p_putc(DMaps[i].cont,f))
33655 {
33656 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
33657 }
33658
33659 if(!p_putc(DMaps[i].type,f))
33660 {
33661 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
33662 }
33663
33664 for(int32_t j=0; j<8; j++)
33665 {
33666 if(!p_putc(DMaps[i].grid[j],f))
33667 {
33668 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
33669 }
33670 }
33671
33672 //16
33673 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
33674 {
33675 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
33676 }
33677
33678 if(!p_putwstr(DMaps[i].title,f))
33679 {
33680 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
33681 }
33682
33683 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
33684 {
33685 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
33686 }
33687
33688 if(!p_iputl(DMaps[i].minimap_tile[0],f))
33689 {
33690 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
33691 }
33692
33693 if(!p_putc(DMaps[i].minimap_cset[0],f))
33694 {
33695 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
33696 }
33697
33698 if(!p_iputl(DMaps[i].minimap_tile[1],f))
33699 {
33700 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
33701 }
33702
33703 if(!p_putc(DMaps[i].minimap_cset[1],f))
33704 {
33705 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
33706 }
33707
33708 if(!p_iputl(DMaps[i].largemap_tile[0],f))
33709 {
33710 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
33711 }
33712
33713 if(!p_putc(DMaps[i].largemap_cset[0],f))
33714 {
33715 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
33716 }
33717
33718 if(!p_iputl(DMaps[i].largemap_tile[1],f))
33719 {
33720 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
33721 }
33722
33723 if(!p_putc(DMaps[i].largemap_cset[1],f))
33724 {
33725 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33726 }
33727
33728 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
33729 {
33730 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33731 }
33732
33733 if(!p_putc(DMaps[i].tmusictrack,f))
33734 {
33735 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33736 }
33737
33738 if(!p_putc(DMaps[i].active_subscreen,f))
33739 {
33740 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33741 }
33742
33743 if(!p_putc(DMaps[i].passive_subscreen,f))
33744 {
33745 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
33746 }
33747
33748 byte disabled[32];
33749 memset(disabled,0,32);
33750
33751 for(int32_t j=0; j<MAXITEMS; j++)
33752 {
33753 if(DMaps[i].disableditems[j])
33754 {
33755 disabled[j/8] |= (1 << (j%8));
33756 }
33757 }
33758
33759 if(!pfwrite(disabled,32,f))
33760 {
33761 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
33762 }
33763
33764 if(!p_iputl(DMaps[i].flags,f))
33765 {
33766 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
33767 }
33768 if(!p_putc(DMaps[i].sideview,f))
33769 {
33770 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
33771 }
33772 if(!p_iputw(DMaps[i].script,f))
33773 {
33774 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
33775 }
33776 for ( int32_t q = 0; q < 8; q++ )
33777 {
33778 if(!p_iputl(DMaps[i].initD[q],f))
33779 {
33780 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
33781 }
33782
33783 }
33784 for ( int32_t q = 0; q < 8; q++ )
33785 {
33786 for ( int32_t w = 0; w < 65; w++ )
33787 {
33788 if (!p_putc(DMaps[i].initD_label[q][w],f))
33789 {
33790 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
33791 }
33792 }
33793 }
33794 }
33795 }
33796 void FFScript::read_dmaps(PACKFILE *f, int32_t vers_id)
33797 {
33798 word dmap_count=count_dmaps();
33799
33800 dmap_count=zc_min(dmap_count, 512);
33801 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
33802
33803 //finally... section data
33804 if(!p_igetw(&dmap_count,f))
33805 {
33806 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
33807 }
33808
33809
33810 for(int32_t i=0; i<dmap_count; i++)
33811 {
33812 if(!p_getc(&DMaps[i].map,f))
33813 {
33814 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
33815 }
33816
33817 if(!p_igetw(&DMaps[i].level,f))
33818 {
33819 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
33820 }
33821
33822 if(!p_getc(&DMaps[i].xoff,f))
33823 {
33824 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
33825 }
33826
33827 if(!p_getc(&DMaps[i].compass,f))
33828 {
33829 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
33830 }
33831
33832 if(!p_igetw(&DMaps[i].color,f))
33833 {
33834 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
33835 }
33836
33837 if(!p_getc(&DMaps[i].midi,f))
33838 {
33839 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
33840 }
33841
33842 if(!p_getc(&DMaps[i].cont,f))
33843 {
33844 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
33845 }
33846
33847 if(!p_getc(&DMaps[i].type,f))
33848 {
33849 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
33850 }
33851
33852 for(int32_t j=0; j<8; j++)
33853 {
33854 if(!p_getc(&DMaps[i].grid[j],f))
33855 {
33856 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
33857 }
33858 }
33859
33860 //16
33861 if(!pfread((&DMaps[i].name),sizeof(DMaps[0].name),f))
33862 {
33863 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
33864 }
33865
33866 if (!p_getwstr(&DMaps[i].title, f))
33867 {
33868 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
33869 }
33870
33871 if(!pfread((&DMaps[i].intro),sizeof(DMaps[0].intro),f))
33872 {
33873 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
33874 }
33875
33876 if(!p_igetl(&DMaps[i].minimap_tile[0],f))
33877 {
33878 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
33879 }
33880
33881 if(!p_getc(&DMaps[i].minimap_cset[0],f))
33882 {
33883 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
33884 }
33885
33886 if(!p_igetl(&DMaps[i].minimap_tile[1],f))
33887 {
33888 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
33889 }
33890
33891 if(!p_getc(&DMaps[i].minimap_cset[1],f))
33892 {
33893 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
33894 }
33895
33896 if(!p_igetl(&DMaps[i].largemap_tile[0],f))
33897 {
33898 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
33899 }
33900
33901 if(!p_getc(&DMaps[i].largemap_cset[0],f))
33902 {
33903 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
33904 }
33905
33906 if(!p_igetl(&DMaps[i].largemap_tile[1],f))
33907 {
33908 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
33909 }
33910
33911 if(!p_getc(&DMaps[i].largemap_cset[1],f))
33912 {
33913 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33914 }
33915
33916 if(!pfread((&DMaps[i].tmusic),sizeof(DMaps[0].tmusic),f))
33917 {
33918 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33919 }
33920
33921 if(!p_getc(&DMaps[i].tmusictrack,f))
33922 {
33923 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33924 }
33925
33926 if(!p_getc(&DMaps[i].active_subscreen,f))
33927 {
33928 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33929 }
33930
33931 if(!p_getc(&DMaps[i].passive_subscreen,f))
33932 {
33933 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
33934 }
33935
33936 byte disabled[32];
33937 memset(disabled,0,32);
33938
33939 for(int32_t j=0; j<MAXITEMS; j++)
33940 {
33941 if(&DMaps[i].disableditems[j])
33942 {
33943 disabled[j/8] |= (1 << (j%8));
33944 }
33945 }
33946
33947 if(!pfread(disabled,32,f))
33948 {
33949 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
33950 }
33951
33952 if(!p_igetl(&DMaps[i].flags,f))
33953 {
33954 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
33955 }
33956 if(!p_getc(&DMaps[i].sideview,f))
33957 {
33958 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
33959 }
33960 if(!p_igetw(&DMaps[i].script,f))
33961 {
33962 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
33963 }
33964 for ( int32_t q = 0; q < 8; q++ )
33965 {
33966 if(!p_igetl(&DMaps[i].initD[q],f))
33967 {
33968 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
33969 }
33970
33971 }
33972 for ( int32_t q = 0; q < 8; q++ )
33973 {
33974 for ( int32_t w = 0; w < 65; w++ )
33975 {
33976 if (!p_getc(&DMaps[i].initD_label[q][w],f))
33977 {
33978 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
33979 }
33980 }
33981 }
33982 }
33983 }
33984
33985
33986
33987 void FFScript::read_combos(PACKFILE *f, int32_t version_id)
33988 {
33989
33990 word combos_used = 0;
33991
33992 if(!p_igetw(&combos_used,f))
33993 {
33994 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
33995 }
33996
33997 for(int32_t i=0; i<combos_used; i++)
33998 {
33999 if(!p_igetl(&combobuf[i].tile,f))
34000 {
34001 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
34002 }
34003
34004 if(!p_getc(&combobuf[i].flip,f))
34005 {
34006 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
34007 }
34008
34009 if(!p_getc(&combobuf[i].walk,f))
34010 {
34011 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
34012 }
34013
34014 if(!p_getc(&combobuf[i].type,f))
34015 {
34016 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
34017 }
34018
34019 if(!p_getc(&combobuf[i].csets,f))
34020 {
34021 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
34022 }
34023
34024 if(!p_getc(&combobuf[i].frames,f))
34025 {
34026 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
34027 }
34028
34029 if(!p_getc(&combobuf[i].speed,f))
34030 {
34031 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
34032 }
34033
34034 if(!p_igetw(&combobuf[i].nextcombo,f))
34035 {
34036 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
34037 }
34038
34039 if(!p_getc(&combobuf[i].nextcset,f))
34040 {
34041 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
34042 }
34043
34044 if(!p_getc(&combobuf[i].flag,f))
34045 {
34046 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
34047 }
34048
34049 if(!p_getc(&combobuf[i].skipanim,f))
34050 {
34051 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
34052 }
34053
34054 if(!p_igetw(&combobuf[i].nexttimer,f))
34055 {
34056 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
34057 }
34058
34059 if(!p_getc(&combobuf[i].skipanimy,f))
34060 {
34061 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
34062 }
34063
34064 if(!p_getc(&combobuf[i].animflags,f))
34065 {
34066 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
34067 }
34068
34069 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34070 {
34071 if(!p_igetl(&combobuf[i].attributes[q],f))
34072 {
34073 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
34074 }
34075 }
34076 if(!p_igetl(&combobuf[i].usrflags,f))
34077 {
34078 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
34079 }
34080 if(combobuf[i].triggers.empty())
34081 combobuf[i].triggers.emplace_back();
34082 if(!p_getbitstr(&combobuf[i].triggers[0].trigger_flags,f))
34083 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
34084
34085 if(!p_igetl(&combobuf[i].triggers[0].triggerlevel,f))
34086 {
34087 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
34088 }
34089 for ( int32_t q = 0; q < 11; q++ )
34090 {
34091 if(!p_getc(&combobuf[i].label[q],f))
34092 {
34093 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
34094 }
34095 }
34096 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34097 {
34098 if(!p_getc(&combobuf[i].attribytes[q],f))
34099 {
34100 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
34101 }
34102 }
34103 if(!p_igetw(&combobuf[i].script,f))
34104 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
34105 for ( int32_t q = 0; q < 2; q++ )
34106 {
34107 if(!p_igetl(&combobuf[i].initd[q],f))
34108 {
34109 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
34110 }
34111 }
34112 if(!p_igetl(&combobuf[i].o_tile,f))
34113 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
34114 if(!p_getc(&combobuf[i].cur_frame,f))
34115 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
34116 if(!p_getc(&combobuf[i].aclk,f))
34117 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
34118 }
34119
34120 combo_caches::refresh();
34121 }
34122
34123 void FFScript::write_combos(PACKFILE *f, int32_t version_id)
34124 {
34125
34126 word combos_used = 0;
34127
34128 //finally... section data
34129 combos_used=count_combos()-0;
34130 combos_used=zc_min(combos_used, MAXCOMBOS);
34131
34132 if(!p_iputw(combos_used,f))
34133 {
34134 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
34135 }
34136
34137 for(int32_t i=0; i<combos_used; i++)
34138 {
34139 if(!p_iputl(combobuf[i].tile,f))
34140 {
34141 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
34142 }
34143
34144 if(!p_putc(combobuf[i].flip,f))
34145 {
34146 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
34147 }
34148
34149 if(!p_putc(combobuf[i].walk,f))
34150 {
34151 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
34152 }
34153
34154 if(!p_putc(combobuf[i].type,f))
34155 {
34156 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
34157 }
34158
34159 if(!p_putc(combobuf[i].csets,f))
34160 {
34161 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
34162 }
34163
34164 if(!p_putc(combobuf[i].frames,f))
34165 {
34166 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
34167 }
34168
34169 if(!p_putc(combobuf[i].speed,f))
34170 {
34171 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
34172 }
34173
34174 if(!p_iputw(combobuf[i].nextcombo,f))
34175 {
34176 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
34177 }
34178
34179 if(!p_putc(combobuf[i].nextcset,f))
34180 {
34181 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
34182 }
34183
34184 if(!p_putc(combobuf[i].flag,f))
34185 {
34186 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
34187 }
34188
34189 if(!p_putc(combobuf[i].skipanim,f))
34190 {
34191 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
34192 }
34193
34194 if(!p_iputw(combobuf[i].nexttimer,f))
34195 {
34196 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
34197 }
34198
34199 if(!p_putc(combobuf[i].skipanimy,f))
34200 {
34201 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
34202 }
34203
34204 if(!p_putc(combobuf[i].animflags,f))
34205 {
34206 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
34207 }
34208
34209 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34210 {
34211 if(!p_iputl(combobuf[i].attributes[q],f))
34212 {
34213 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
34214 }
34215 }
34216 if(!p_iputl(combobuf[i].usrflags,f))
34217 {
34218 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
34219 }
34220 if(combobuf[i].triggers.empty())
34221 combobuf[i].triggers.emplace_back();
34222 if(!p_putbitstr(combobuf[i].triggers[0].trigger_flags,f));
34223 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
34224
34225 if(!p_iputl(combobuf[i].triggers[0].triggerlevel,f))
34226 {
34227 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
34228 }
34229 for ( int32_t q = 0; q < 11; q++ )
34230 {
34231 if(!p_putc(combobuf[i].label[q],f))
34232 {
34233 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
34234 }
34235 }
34236 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34237 {
34238 if(!p_putc(combobuf[i].attribytes[q],f))
34239 {
34240 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
34241 }
34242 }
34243 if(!p_iputw(combobuf[i].script,f))
34244 {
34245 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
34246 }
34247 for ( int32_t q = 0; q < 2; q++ )
34248 {
34249 if(!p_iputl(combobuf[i].initd[q],f))
34250 {
34251 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
34252 }
34253 }
34254 if(!p_iputl(combobuf[i].o_tile,f))
34255 {
34256 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
34257 }
34258 if(!p_putc(combobuf[i].cur_frame,f))
34259 {
34260 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
34261 }
34262 if(!p_putc(combobuf[i].aclk,f))
34263 {
34264 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
34265 }
34266
34267 }
34268 }
34269 void FFScript::read_weaponsprtites(PACKFILE *f, int32_t vers_id)
34270 {
34271 for(int32_t i=0; i<MAXWPNS; i++)
34272 {
34273 word oldtile = 0;
34274 if(!p_igetw(&oldtile,f))
34275 {
34276 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
34277 }
34278
34279 if(!p_getc(&wpnsbuf[i].misc,f))
34280 {
34281 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
34282 }
34283
34284 if(!p_getc(&wpnsbuf[i].csets,f))
34285 {
34286 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
34287 }
34288
34289 if(!p_getc(&wpnsbuf[i].frames,f))
34290 {
34291 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
34292 }
34293
34294 if(!p_getc(&wpnsbuf[i].speed,f))
34295 {
34296 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
34297 }
34298
34299 if(!p_getc(&wpnsbuf[i].type,f))
34300 {
34301 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
34302 }
34303
34304 if(!p_igetw(&wpnsbuf[i].script,f))
34305 {
34306 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34307 }
34308
34309 if(!p_igetl(&wpnsbuf[i].tile,f))
34310 {
34311 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34312 }
34313 }
34314 }
34315 void FFScript::write_weaponsprtites(PACKFILE *f, int32_t vers_id)
34316 {
34317 for(int32_t i=0; i<MAXWPNS; i++)
34318 {
34319 if(!p_iputw(wpnsbuf[i].tile,f))
34320 {
34321 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
34322 }
34323
34324 if(!p_putc(wpnsbuf[i].misc,f))
34325 {
34326 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
34327 }
34328
34329 if(!p_putc(wpnsbuf[i].csets,f))
34330 {
34331 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
34332 }
34333
34334 if(!p_putc(wpnsbuf[i].frames,f))
34335 {
34336 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
34337 }
34338
34339 if(!p_putc(wpnsbuf[i].speed,f))
34340 {
34341 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
34342 }
34343
34344 if(!p_putc(wpnsbuf[i].type,f))
34345 {
34346 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
34347 }
34348
34349 if(!p_iputw(wpnsbuf[i].script,f))
34350 {
34351 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34352 }
34353
34354 if(!p_iputl(wpnsbuf[i].tile,f))
34355 {
34356 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34357 }
34358 }
34359 }
34360
34361
34362 void FFScript::read_enemies(PACKFILE *f, int32_t vers_id)
34363 {
34364 if ( !f ) return;
34365 for(int32_t i=0; i<MAXGUYS; i++)
34366 {
34367 uint32_t flags1;
34368 uint32_t flags2;
34369 if (!p_igetl(&(flags1), f))
34370 {
34371 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 6);
34372 }
34373 if (!p_igetl(&(flags2), f))
34374 {
34375 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 7);;
34376 }
34377 guysbuf[i].flags = guy_flags(flags1) | guy_flags(uint64_t(flags2) << 32ULL);
34378
34379 if(!p_igetl(&guysbuf[i].tile,f))
34380 {
34381 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",8);
34382 }
34383
34384 if(!p_getc(&guysbuf[i].width,f))
34385 {
34386 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",9);
34387 }
34388
34389 if(!p_getc(&guysbuf[i].height,f))
34390 {
34391 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",10);
34392 }
34393
34394 if(!p_igetl(&guysbuf[i].s_tile,f))
34395 {
34396 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",11);
34397 }
34398
34399 if(!p_getc(&guysbuf[i].s_width,f))
34400 {
34401 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",12);
34402 }
34403
34404 if(!p_getc(&guysbuf[i].s_height,f))
34405 {
34406 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",13);
34407 }
34408
34409 if(!p_igetl(&guysbuf[i].e_tile,f))
34410 {
34411 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",14);
34412 }
34413
34414 if(!p_getc(&guysbuf[i].e_width,f))
34415 {
34416 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",15);
34417 }
34418
34419 if(!p_getc(&guysbuf[i].e_height,f))
34420 {
34421 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",16);
34422 }
34423
34424 if(!p_igetw(&guysbuf[i].hp,f))
34425 {
34426 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",17);
34427 }
34428
34429 if(!p_igetw(&guysbuf[i].family,f))
34430 {
34431 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",18);
34432 }
34433
34434 if(!p_igetw(&guysbuf[i].cset,f))
34435 {
34436 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",19);
34437 }
34438
34439 if(!p_igetw(&guysbuf[i].anim,f))
34440 {
34441 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",20);
34442 }
34443
34444 if(!p_igetw(&guysbuf[i].e_anim,f))
34445 {
34446 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",21);
34447 }
34448
34449 if(!p_igetw(&guysbuf[i].frate,f))
34450 {
34451 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",22);
34452 }
34453
34454 if(!p_igetw(&guysbuf[i].e_frate,f))
34455 {
34456 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",23);
34457 }
34458
34459 if(!p_igetw(&guysbuf[i].dp,f))
34460 {
34461 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",24);
34462 }
34463
34464 if(!p_igetw(&guysbuf[i].wdp,f))
34465 {
34466 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",25);
34467 }
34468
34469 if(!p_igetw(&guysbuf[i].weapon,f))
34470 {
34471 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",26);
34472 }
34473
34474 if(!p_igetw(&guysbuf[i].rate,f))
34475 {
34476 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",27);
34477 }
34478
34479 if(!p_igetw(&guysbuf[i].hrate,f))
34480 {
34481 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",28);
34482 }
34483
34484 if(!p_igetw(&guysbuf[i].step,f))
34485 {
34486 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",29);
34487 }
34488
34489 if(!p_igetw(&guysbuf[i].homing,f))
34490 {
34491 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",30);
34492 }
34493
34494 if(!p_igetw(&guysbuf[i].grumble,f))
34495 {
34496 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",31);
34497 }
34498
34499 if(!p_igetw(&guysbuf[i].item_set,f))
34500 {
34501 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",32);
34502 }
34503 //misc 1-10
34504 for (int q = 0; q < 10; ++q)
34505 {
34506 if (!p_igetl(&guysbuf[i].attributes[q], f))
34507 {
34508 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 33 + q);
34509 }
34510 }
34511
34512 if(!p_igetw(&guysbuf[i].bgsfx,f))
34513 {
34514 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",43);
34515 }
34516
34517 if(!p_igetw(&guysbuf[i].bosspal,f))
34518 {
34519 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",44);
34520 }
34521
34522 if(!p_igetw(&guysbuf[i].extend,f))
34523 {
34524 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",45);
34525 }
34526
34527 for(int32_t j=0; j < edefLAST; j++)
34528 {
34529 if(!p_getc(&guysbuf[i].defense[j],f))
34530 {
34531 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",46);
34532 }
34533 }
34534
34535 if(!p_getc(&guysbuf[i].hitsfx,f))
34536 {
34537 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",47);
34538 }
34539
34540 if(!p_getc(&guysbuf[i].deadsfx,f))
34541 {
34542 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",48);
34543 }
34544 //misc 11-12
34545 for (int q = 0; q < 2; ++q)
34546 {
34547 if (!p_igetl(&guysbuf[i].attributes[10+q], f))
34548 {
34549 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 49 + q);
34550 }
34551 }
34552
34553 //New 2.6 defences
34554 for(int32_t j=edefLAST; j < edefLAST255; j++)
34555 {
34556 if(!p_getc(&guysbuf[i].defense[j],f))
34557 {
34558 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",51);
34559 }
34560 }
34561
34562 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
34563 if(!p_igetl(&guysbuf[i].txsz,f))
34564 {
34565 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",52);
34566 }
34567 if(!p_igetl(&guysbuf[i].tysz,f))
34568 {
34569 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",53);
34570 }
34571 if(!p_igetl(&guysbuf[i].hxsz,f))
34572 {
34573 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",54);
34574 }
34575 if(!p_igetl(&guysbuf[i].hysz,f))
34576 {
34577 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",55);
34578 }
34579 if(!p_igetl(&guysbuf[i].hzsz,f))
34580 {
34581 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",56);
34582 }
34583 // These are not fixed types, but ints, so they are safe to use here.
34584 if(!p_igetl(&guysbuf[i].hxofs,f))
34585 {
34586 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",57);
34587 }
34588 if(!p_igetl(&guysbuf[i].hyofs,f))
34589 {
34590 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",58);
34591 }
34592 if(!p_igetl(&guysbuf[i].xofs,f))
34593 {
34594 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",59);
34595 }
34596 if(!p_igetl(&guysbuf[i].yofs,f))
34597 {
34598 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",60);
34599 }
34600 if(!p_igetl(&guysbuf[i].zofs,f))
34601 {
34602 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",61);
34603 }
34604 if(!p_igetl(&guysbuf[i].wpnsprite,f))
34605 {
34606 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",62);
34607 }
34608 if(!p_igetl(&guysbuf[i].SIZEflags,f))
34609 {
34610 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",63);
34611 }
34612 if(!p_igetl(&guysbuf[i].frozentile,f))
34613 {
34614 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",64);
34615 }
34616 if(!p_igetl(&guysbuf[i].frozencset,f))
34617 {
34618 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",65);
34619 }
34620 if(!p_igetl(&guysbuf[i].frozenclock,f))
34621 {
34622 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",66);
34623 }
34624
34625 for ( int32_t q = 0; q < 10; q++ )
34626 {
34627 if(!p_igetw(&guysbuf[i].frozenmisc[q],f))
34628 {
34629 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",67);
34630 }
34631 }
34632 if(!p_igetw(&guysbuf[i].firesfx,f))
34633 {
34634 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",68);
34635 }
34636 //misc 16->32
34637 for (int q = 0; q < 17; ++q)
34638 {
34639 if (!p_igetl(&guysbuf[i].attributes[15 + q], f))
34640 {
34641 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 69 + q);
34642 }
34643 }
34644 for ( int32_t q = 0; q < 32; q++ )
34645 {
34646 if(!p_igetl(&guysbuf[i].movement[q],f))
34647 {
34648 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",86);
34649 }
34650 }
34651 for ( int32_t q = 0; q < 32; q++ )
34652 {
34653 if(!p_igetl(&guysbuf[i].new_weapon[q],f))
34654 {
34655 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",87);
34656 }
34657 }
34658 if(!p_igetw(&guysbuf[i].script,f))
34659 {
34660 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",88);
34661 }
34662 for ( int32_t q = 0; q < 8; q++ )
34663 {
34664 if(!p_igetl(&guysbuf[i].initD[q],f))
34665 {
34666 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",89);
34667 }
34668 }
34669 if(!p_igetl(&guysbuf[i].editorflags,f))
34670 {
34671 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",91);
34672 }
34673 //somehow forgot these in the older builds -Z
34674 for (int q = 0; q < 3; ++q)
34675 {
34676 if (!p_igetl(&guysbuf[i].attributes[12 + q], f))
34677 {
34678 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 92 + q);
34679 }
34680 }
34681
34682 //Enemy Editor InitD[] labels
34683 for ( int32_t q = 0; q < 8; q++ )
34684 {
34685 for ( int32_t w = 0; w < 65; w++ )
34686 {
34687 if(!p_getc(&guysbuf[i].initD_label[q][w],f))
34688 {
34689 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",95);
34690 }
34691 }
34692 byte dummy;
34693 for ( int32_t w = 0; w < 65; w++ )
34694 {
34695 if(!p_getc(&dummy,f))
34696 {
34697 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",96);
34698 }
34699 }
34700 }
34701 if(!p_igetw(&guysbuf[i].weap_data.script,f))
34702 {
34703 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",97);
34704 }
34705 //eweapon initD
34706 for ( int32_t q = 0; q < 8; q++ )
34707 {
34708 if(!p_igetl(&guysbuf[i].weap_data.initd[q],f))
34709 {
34710 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",98);
34711 }
34712 }
34713
34714
34715 }
34716 }
34717
34718 void FFScript::write_enemies(PACKFILE *f, int32_t vers_id)
34719 {
34720 if ( !f ) return;
34721 for(int32_t i=0; i<MAXGUYS; i++)
34722 {
34723 uint32_t flags1 = uint32_t(guysbuf[i].flags);
34724 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
34725 if (!p_iputl(flags1, f))
34726 {
34727 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 6);
34728 }
34729 if (!p_iputl(flags2, f))
34730 {
34731 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 7);
34732 }
34733
34734 if(!p_iputl(guysbuf[i].tile,f))
34735 {
34736 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",8);
34737 }
34738
34739 if(!p_putc(guysbuf[i].width,f))
34740 {
34741 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",9);
34742 }
34743
34744 if(!p_putc(guysbuf[i].height,f))
34745 {
34746 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",10);
34747 }
34748
34749 if(!p_iputl(guysbuf[i].s_tile,f))
34750 {
34751 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",11);
34752 }
34753
34754 if(!p_putc(guysbuf[i].s_width,f))
34755 {
34756 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",12);
34757 }
34758
34759 if(!p_putc(guysbuf[i].s_height,f))
34760 {
34761 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",13);
34762 }
34763
34764 if(!p_iputl(guysbuf[i].e_tile,f))
34765 {
34766 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",14);
34767 }
34768
34769 if(!p_putc(guysbuf[i].e_width,f))
34770 {
34771 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",15);
34772 }
34773
34774 if(!p_putc(guysbuf[i].e_height,f))
34775 {
34776 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",16);
34777 }
34778
34779 if(!p_iputw(guysbuf[i].hp,f))
34780 {
34781 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",17);
34782 }
34783
34784 if(!p_iputw(guysbuf[i].family,f))
34785 {
34786 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",18);
34787 }
34788
34789 if(!p_iputw(guysbuf[i].cset,f))
34790 {
34791 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",19);
34792 }
34793
34794 if(!p_iputw(guysbuf[i].anim,f))
34795 {
34796 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",20);
34797 }
34798
34799 if(!p_iputw(guysbuf[i].e_anim,f))
34800 {
34801 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",21);
34802 }
34803
34804 if(!p_iputw(guysbuf[i].frate,f))
34805 {
34806 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",22);
34807 }
34808
34809 if(!p_iputw(guysbuf[i].e_frate,f))
34810 {
34811 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",23);
34812 }
34813
34814 if(!p_iputw(guysbuf[i].dp,f))
34815 {
34816 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",24);
34817 }
34818
34819 if(!p_iputw(guysbuf[i].wdp,f))
34820 {
34821 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",25);
34822 }
34823
34824 if(!p_iputw(guysbuf[i].weapon,f))
34825 {
34826 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",26);
34827 }
34828
34829 if(!p_iputw(guysbuf[i].rate,f))
34830 {
34831 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",27);
34832 }
34833
34834 if(!p_iputw(guysbuf[i].hrate,f))
34835 {
34836 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",28);
34837 }
34838
34839 if(!p_iputw(guysbuf[i].step,f))
34840 {
34841 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",29);
34842 }
34843
34844 if(!p_iputw(guysbuf[i].homing,f))
34845 {
34846 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",30);
34847 }
34848
34849 if(!p_iputw(guysbuf[i].grumble,f))
34850 {
34851 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",31);
34852 }
34853
34854 if(!p_iputw(guysbuf[i].item_set,f))
34855 {
34856 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",32);
34857 }
34858
34859 //misc 1-10
34860 for (int q = 0; q < 10; ++q)
34861 {
34862 if (!p_iputl(guysbuf[i].attributes[q], f))
34863 {
34864 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 33+q);
34865 }
34866 }
34867
34868 if(!p_iputw(guysbuf[i].bgsfx,f))
34869 {
34870 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",43);
34871 }
34872
34873 if(!p_iputw(guysbuf[i].bosspal,f))
34874 {
34875 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",44);
34876 }
34877
34878 if(!p_iputw(guysbuf[i].extend,f))
34879 {
34880 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",45);
34881 }
34882
34883 for(int32_t j=0; j < edefLAST; j++)
34884 {
34885 if(!p_putc(guysbuf[i].defense[j],f))
34886 {
34887 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",46);
34888 }
34889 }
34890
34891 if(!p_putc(guysbuf[i].hitsfx,f))
34892 {
34893 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",47);
34894 }
34895
34896 if(!p_putc(guysbuf[i].deadsfx,f))
34897 {
34898 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",48);
34899 }
34900
34901 //misc 11-12
34902 for (int q = 0; q < 2; ++q)
34903 {
34904 if (!p_iputl(guysbuf[i].attributes[10+q], f))
34905 {
34906 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 49 + q);
34907 }
34908 }
34909
34910 //New 2.6 defences
34911 for(int32_t j=edefLAST; j < edefLAST255; j++)
34912 {
34913 if(!p_putc(guysbuf[i].defense[j],f))
34914 {
34915 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",51);
34916 }
34917 }
34918
34919 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
34920 if(!p_iputl(guysbuf[i].txsz,f))
34921 {
34922 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",52);
34923 }
34924 if(!p_iputl(guysbuf[i].tysz,f))
34925 {
34926 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",53);
34927 }
34928 if(!p_iputl(guysbuf[i].hxsz,f))
34929 {
34930 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",54);
34931 }
34932 if(!p_iputl(guysbuf[i].hysz,f))
34933 {
34934 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",55);
34935 }
34936 if(!p_iputl(guysbuf[i].hzsz,f))
34937 {
34938 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",56);
34939 }
34940 // These are not fixed types, but ints, so they are safe to use here.
34941 if(!p_iputl(guysbuf[i].hxofs,f))
34942 {
34943 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",57);
34944 }
34945 if(!p_iputl(guysbuf[i].hyofs,f))
34946 {
34947 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",58);
34948 }
34949 if(!p_iputl(guysbuf[i].xofs,f))
34950 {
34951 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",59);
34952 }
34953 if(!p_iputl(guysbuf[i].yofs,f))
34954 {
34955 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",60);
34956 }
34957 if(!p_iputl(guysbuf[i].zofs,f))
34958 {
34959 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",61);
34960 }
34961 if(!p_iputl(guysbuf[i].wpnsprite,f))
34962 {
34963 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",62);
34964 }
34965 if(!p_iputl(guysbuf[i].SIZEflags,f))
34966 {
34967 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",63);
34968 }
34969 if(!p_iputl(guysbuf[i].frozentile,f))
34970 {
34971 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",64);
34972 }
34973 if(!p_iputl(guysbuf[i].frozencset,f))
34974 {
34975 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",65);
34976 }
34977 if(!p_iputl(guysbuf[i].frozenclock,f))
34978 {
34979 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",66);
34980 }
34981
34982 for ( int32_t q = 0; q < 10; q++ )
34983 {
34984 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
34985 {
34986 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",67);
34987 }
34988 }
34989
34990 if(!p_iputw(guysbuf[i].firesfx,f))
34991 {
34992 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",68);
34993 }
34994 //misc 16->32
34995 for (int q=0; q < 17; ++q)
34996 {
34997 if (!p_iputl(guysbuf[i].attributes[15 + q], f))
34998 {
34999 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 69 + q);
35000 }
35001 }
35002 for ( int32_t q = 0; q < 32; q++ )
35003 {
35004 if(!p_iputl(guysbuf[i].movement[q],f))
35005 {
35006 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",86);
35007 }
35008 }
35009 for ( int32_t q = 0; q < 32; q++ )
35010 {
35011 if(!p_iputl(guysbuf[i].new_weapon[q],f))
35012 {
35013 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",87);
35014 }
35015 }
35016 if(!p_iputw(guysbuf[i].script,f))
35017 {
35018 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",88);
35019 }
35020 for ( int32_t q = 0; q < 8; q++ )
35021 {
35022 if(!p_iputl(guysbuf[i].initD[q],f))
35023 {
35024 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",89);
35025 }
35026 }
35027 if(!p_iputl(guysbuf[i].editorflags,f))
35028 {
35029 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",91);
35030 }
35031 //misc 13-15
35032 for (int q = 0; q < 4; ++q)
35033 {
35034 if (!p_iputl(guysbuf[i].attributes[12 + q], f))
35035 {
35036 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 92 + q);
35037 }
35038 }
35039
35040 //Enemy Editor InitD[] labels
35041 for ( int32_t q = 0; q < 8; q++ )
35042 {
35043 for ( int32_t w = 0; w < 65; w++ )
35044 {
35045 if(!p_putc(guysbuf[i].initD_label[q][w],f))
35046 {
35047 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",95);
35048 }
35049 }
35050 for ( int32_t w = 0; w < 65; w++ )
35051 {
35052 if(!p_putc(0,f))
35053 {
35054 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",96);
35055 }
35056 }
35057 }
35058 if(!p_iputw(guysbuf[i].weap_data.script,f))
35059 {
35060 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",97);
35061 }
35062 //eweapon initD
35063 for ( int32_t q = 0; q < 8; q++ )
35064 {
35065 if(!p_iputl(guysbuf[i].weap_data.initd[q],f))
35066 {
35067 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",98);
35068 }
35069 }
35070
35071 }
35072 }
35073
35074
35075 void FFScript::write_items(PACKFILE *f, int32_t vers_id)
35076 {
35077 for(int32_t i=0; i<MAXITEMS; i++)
35078 {
35079 if(!p_iputl(itemsbuf[i].tile,f))
35080 {
35081 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",6);
35082 }
35083
35084 if(!p_putc(itemsbuf[i].misc_flags,f))
35085 {
35086 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",7);
35087 }
35088
35089 if(!p_putc(itemsbuf[i].csets,f))
35090 {
35091 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",8);
35092 }
35093
35094 if(!p_putc(itemsbuf[i].frames,f))
35095 {
35096 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",9);
35097 }
35098
35099 if(!p_putc(itemsbuf[i].speed,f))
35100 {
35101 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",10);
35102 }
35103
35104 if(!p_putc(itemsbuf[i].delay,f))
35105 {
35106 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",11);
35107 }
35108
35109 if(!p_iputl(itemsbuf[i].ltm,f))
35110 {
35111 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",12);
35112 }
35113
35114 if(!p_iputl(itemsbuf[i].family,f))
35115 {
35116 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",13);
35117 }
35118
35119 if(!p_putc(itemsbuf[i].fam_type,f))
35120 {
35121 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
35122 }
35123
35124 if(!p_iputl(itemsbuf[i].power,f))
35125 {
35126 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
35127 }
35128
35129 if(!p_iputl(itemsbuf[i].flags,f))
35130 {
35131 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",15);
35132 }
35133
35134 if(!p_iputw(itemsbuf[i].script,f))
35135 {
35136 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",16);
35137 }
35138
35139 if(!p_putc(itemsbuf[i].count,f))
35140 {
35141 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",17);
35142 }
35143
35144 if(!p_iputw(itemsbuf[i].amount,f))
35145 {
35146 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",18);
35147 }
35148
35149 if(!p_iputw(itemsbuf[i].collect_script,f))
35150 {
35151 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",19);
35152 }
35153
35154 if(!p_iputw(itemsbuf[i].setmax,f))
35155 {
35156 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",21);
35157 }
35158
35159 if(!p_iputw(itemsbuf[i].max,f))
35160 {
35161 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",22);
35162 }
35163
35164 if(!p_putc(itemsbuf[i].playsound,f))
35165 {
35166 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",23);
35167 }
35168
35169 for(int32_t j=0; j<8; j++)
35170 {
35171 if(!p_iputl(itemsbuf[i].initiald[j],f))
35172 {
35173 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",24);
35174 }
35175 }
35176
35177 if(!p_putc(itemsbuf[i].wpn,f))
35178 {
35179 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",26);
35180 }
35181
35182 if(!p_putc(itemsbuf[i].wpn2,f))
35183 {
35184 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",27);
35185 }
35186
35187 if(!p_putc(itemsbuf[i].wpn3,f))
35188 {
35189 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",28);
35190 }
35191
35192 if(!p_putc(itemsbuf[i].wpn4,f))
35193 {
35194 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",29);
35195 }
35196
35197 if(!p_putc(itemsbuf[i].wpn5,f))
35198 {
35199 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",30);
35200 }
35201
35202 if(!p_putc(itemsbuf[i].wpn6,f))
35203 {
35204 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",31);
35205 }
35206
35207 if(!p_putc(itemsbuf[i].wpn7,f))
35208 {
35209 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",32);
35210 }
35211
35212 if(!p_putc(itemsbuf[i].wpn8,f))
35213 {
35214 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",33);
35215 }
35216
35217 if(!p_putc(itemsbuf[i].wpn9,f))
35218 {
35219 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",34);
35220 }
35221
35222 if(!p_putc(itemsbuf[i].wpn10,f))
35223 {
35224 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",35);
35225 }
35226
35227 if(!p_putc(itemsbuf[i].pickup_hearts,f))
35228 {
35229 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",36);
35230 }
35231
35232 if(!p_iputl(itemsbuf[i].misc1,f))
35233 {
35234 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",37);
35235 }
35236
35237 if(!p_iputl(itemsbuf[i].misc2,f))
35238 {
35239 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",38);
35240 }
35241
35242 if(!p_putc(itemsbuf[i].cost_amount[0],f))
35243 {
35244 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",39);
35245 }
35246
35247 if(!p_iputl(itemsbuf[i].misc3,f))
35248 {
35249 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",40);
35250 }
35251
35252 if(!p_iputl(itemsbuf[i].misc4,f))
35253 {
35254 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",41);
35255 }
35256
35257 if(!p_iputl(itemsbuf[i].misc5,f))
35258 {
35259 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",42);
35260 }
35261
35262 if(!p_iputl(itemsbuf[i].misc6,f))
35263 {
35264 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",43);
35265 }
35266
35267 if(!p_iputl(itemsbuf[i].misc7,f))
35268 {
35269 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",44);
35270 }
35271
35272 if(!p_iputl(itemsbuf[i].misc8,f))
35273 {
35274 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",45);
35275 }
35276
35277 if(!p_iputl(itemsbuf[i].misc9,f))
35278 {
35279 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",46);
35280 }
35281
35282 if(!p_iputl(itemsbuf[i].misc10,f))
35283 {
35284 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",47);
35285 }
35286
35287 if(!p_putc(itemsbuf[i].usesound,f))
35288 {
35289 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
35290 }
35291
35292 if(!p_putc(itemsbuf[i].usesound2,f))
35293 {
35294 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
35295 }
35296
35297 //New itemdata vars -Z
35298 //! version 27
35299
35300 if(!p_putc(itemsbuf[i].weap_data.imitate_weapon,f))
35301 {
35302 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",49);
35303 }
35304 if(!p_putc(itemsbuf[i].weap_data.default_defense,f))
35305 {
35306 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",50);
35307 }
35308 if(!p_iputl(itemsbuf[i].weaprange,f))
35309 {
35310 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",51);
35311 }
35312 if(!p_iputl(itemsbuf[i].weapduration,f))
35313 {
35314 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",52);
35315 }
35316 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
35317 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
35318 {
35319 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",53);
35320 }
35321 }
35322 //version 28
35323 if(!p_iputl(itemsbuf[i].duplicates,f))
35324 {
35325 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",54);
35326 }
35327 for ( int32_t q = 0; q < INITIAL_D; q++ )
35328 {
35329 if(!p_iputl(itemsbuf[i].weap_data.initd[q],f))
35330 {
35331 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",55);
35332 }
35333 }
35334
35335 if(!p_putc(itemsbuf[i].drawlayer,f))
35336 {
35337 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",57);
35338 }
35339
35340
35341 if(!p_iputl(itemsbuf[i].hxofs,f))
35342 {
35343 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",58);
35344 }
35345 if(!p_iputl(itemsbuf[i].hyofs,f))
35346 {
35347 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",59);
35348 }
35349 if(!p_iputl(itemsbuf[i].hxsz,f))
35350 {
35351 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",60);
35352 }
35353 if(!p_iputl(itemsbuf[i].hysz,f))
35354 {
35355 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",61);
35356 }
35357 if(!p_iputl(itemsbuf[i].hzsz,f))
35358 {
35359 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",62);
35360 }
35361 if(!p_iputl(itemsbuf[i].xofs,f))
35362 {
35363 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",63);
35364 }
35365 if(!p_iputl(itemsbuf[i].yofs,f))
35366 {
35367 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",64);
35368 }
35369 if(!p_iputl(itemsbuf[i].weap_data.hxofs,f))
35370 {
35371 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",65);
35372 }
35373 if(!p_iputl(itemsbuf[i].weap_data.hyofs,f))
35374 {
35375 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",66);
35376 }
35377 if(!p_iputl(itemsbuf[i].weap_data.hxsz,f))
35378 {
35379 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",67);
35380 }
35381 if(!p_iputl(itemsbuf[i].weap_data.hysz,f))
35382 {
35383 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",68);
35384 }
35385 if(!p_iputl(itemsbuf[i].weap_data.hzsz,f))
35386 {
35387 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",69);
35388 }
35389 if(!p_iputl(itemsbuf[i].weap_data.xofs,f))
35390 {
35391 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",70);
35392 }
35393 if(!p_iputl(itemsbuf[i].weap_data.yofs,f))
35394 {
35395 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",71);
35396 }
35397 if(!p_iputw(itemsbuf[i].weap_data.script,f))
35398 {
35399 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",72);
35400 }
35401 if(!p_iputl(itemsbuf[i].wpnsprite,f))
35402 {
35403 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",73);
35404 }
35405 if(!p_iputl(itemsbuf[i].magiccosttimer[0],f))
35406 {
35407 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",74);
35408 }
35409 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
35410 {
35411 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",75);
35412 }
35413 if(!p_iputl(itemsbuf[i].tilew,f))
35414 {
35415 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",76);
35416 }
35417 if(!p_iputl(itemsbuf[i].tileh,f))
35418 {
35419 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",77);
35420 }
35421 if(!p_iputl(itemsbuf[i].weap_data.override_flags,f))
35422 {
35423 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",78);
35424 }
35425 if(!p_iputl(itemsbuf[i].weap_data.tilew,f))
35426 {
35427 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",79);
35428 }
35429 if(!p_iputl(itemsbuf[i].weap_data.tileh,f))
35430 {
35431 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",80);
35432 }
35433 if(!p_iputl(itemsbuf[i].pickup,f))
35434 {
35435 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",81);
35436 }
35437 if(!p_iputw(itemsbuf[i].pstring,f))
35438 {
35439 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",82);
35440 }
35441 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
35442 {
35443 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",83);
35444 }
35445
35446 if(!p_putc(itemsbuf[i].cost_counter[0],f))
35447 {
35448 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",84);
35449 }
35450
35451 //InitD[] labels
35452 for ( int32_t q = 0; q < 8; q++ )
35453 {
35454 for ( int32_t w = 0; w < 65; w++ )
35455 {
35456 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
35457 {
35458 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",85);
35459 }
35460 }
35461 for ( int32_t w = 0; w < 65; w++ )
35462 {
35463 if(!p_putc(0,f))
35464 {
35465 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",86);
35466 }
35467 }
35468 for ( int32_t w = 0; w < 65; w++ )
35469 {
35470 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
35471 {
35472 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",87);
35473 }
35474 }
35475 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
35476 {
35477 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",88);
35478 }
35479 }
35480
35481 if(!p_iputw(itemsbuf[i].sprite_script,f))
35482 {
35483 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",90);
35484 }
35485
35486
35487 }
35488 }
35489
35490 void FFScript::read_items(PACKFILE *f, int32_t vers_id)
35491 {
35492 for(int32_t i=0; i<MAXITEMS; i++)
35493 {
35494 if(!p_igetl(&itemsbuf[i].tile,f))
35495 {
35496 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",6);
35497 }
35498
35499 if(!p_getc(&itemsbuf[i].misc_flags,f))
35500 {
35501 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",7);
35502 }
35503
35504 if(!p_getc(&itemsbuf[i].csets,f))
35505 {
35506 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",8);
35507 }
35508
35509 if(!p_getc(&itemsbuf[i].frames,f))
35510 {
35511 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",9);
35512 }
35513
35514 if(!p_getc(&itemsbuf[i].speed,f))
35515 {
35516 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",10);
35517 }
35518
35519 if(!p_getc(&itemsbuf[i].delay,f))
35520 {
35521 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",11);
35522 }
35523
35524 if(!p_igetl(&itemsbuf[i].ltm,f))
35525 {
35526 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",12);
35527 }
35528
35529 if(!p_igetl(&itemsbuf[i].family,f))
35530 {
35531 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",13);
35532 }
35533
35534 if(!p_getc(&itemsbuf[i].fam_type,f))
35535 {
35536 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
35537 }
35538
35539 if(!p_igetl(&itemsbuf[i].power,f))
35540 {
35541 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
35542 }
35543
35544 if(!p_igetl(&itemsbuf[i].flags,f))
35545 {
35546 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",15);
35547 }
35548
35549 if(!p_igetw(&itemsbuf[i].script,f))
35550 {
35551 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",16);
35552 }
35553
35554 if(!p_getc(&itemsbuf[i].count,f))
35555 {
35556 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",17);
35557 }
35558
35559 if(!p_igetw(&itemsbuf[i].amount,f))
35560 {
35561 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",18);
35562 }
35563
35564 if(!p_igetw(&itemsbuf[i].collect_script,f))
35565 {
35566 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",19);
35567 }
35568
35569 if(!p_igetw(&itemsbuf[i].setmax,f))
35570 {
35571 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",21);
35572 }
35573
35574 if(!p_igetw(&itemsbuf[i].max,f))
35575 {
35576 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",22);
35577 }
35578
35579 if(!p_getc(&itemsbuf[i].playsound,f))
35580 {
35581 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",23);
35582 }
35583
35584 for(int32_t j=0; j<8; j++)
35585 {
35586 if(!p_igetl(&itemsbuf[i].initiald[j],f))
35587 {
35588 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",24);
35589 }
35590 }
35591
35592 if(!p_getc(&itemsbuf[i].wpn,f))
35593 {
35594 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",26);
35595 }
35596
35597 if(!p_getc(&itemsbuf[i].wpn2,f))
35598 {
35599 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",27);
35600 }
35601
35602 if(!p_getc(&itemsbuf[i].wpn3,f))
35603 {
35604 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",28);
35605 }
35606
35607 if(!p_getc(&itemsbuf[i].wpn4,f))
35608 {
35609 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",29);
35610 }
35611
35612 if(!p_getc(&itemsbuf[i].wpn5,f))
35613 {
35614 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",30);
35615 }
35616
35617 if(!p_getc(&itemsbuf[i].wpn6,f))
35618 {
35619 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",31);
35620 }
35621
35622 if(!p_getc(&itemsbuf[i].wpn7,f))
35623 {
35624 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",32);
35625 }
35626
35627 if(!p_getc(&itemsbuf[i].wpn8,f))
35628 {
35629 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",33);
35630 }
35631
35632 if(!p_getc(&itemsbuf[i].wpn9,f))
35633 {
35634 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",34);
35635 }
35636
35637 if(!p_getc(&itemsbuf[i].wpn10,f))
35638 {
35639 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",35);
35640 }
35641
35642 if(!p_getc(&itemsbuf[i].pickup_hearts,f))
35643 {
35644 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",36);
35645 }
35646
35647 if(!p_igetl(&itemsbuf[i].misc1,f))
35648 {
35649 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",37);
35650 }
35651
35652 if(!p_igetl(&itemsbuf[i].misc2,f))
35653 {
35654 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",38);
35655 }
35656
35657 if(!p_getc(&itemsbuf[i].cost_amount[0],f))
35658 {
35659 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",39);
35660 }
35661
35662 if(!p_igetl(&itemsbuf[i].misc3,f))
35663 {
35664 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",40);
35665 }
35666
35667 if(!p_igetl(&itemsbuf[i].misc4,f))
35668 {
35669 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",41);
35670 }
35671
35672 if(!p_igetl(&itemsbuf[i].misc5,f))
35673 {
35674 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",42);
35675 }
35676
35677 if(!p_igetl(&itemsbuf[i].misc6,f))
35678 {
35679 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",43);
35680 }
35681
35682 if(!p_igetl(&itemsbuf[i].misc7,f))
35683 {
35684 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",44);
35685 }
35686
35687 if(!p_igetl(&itemsbuf[i].misc8,f))
35688 {
35689 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",45);
35690 }
35691
35692 if(!p_igetl(&itemsbuf[i].misc9,f))
35693 {
35694 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",46);
35695 }
35696
35697 if(!p_igetl(&itemsbuf[i].misc10,f))
35698 {
35699 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",47);
35700 }
35701
35702 if(!p_getc(&itemsbuf[i].usesound,f))
35703 {
35704 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
35705 }
35706
35707 if(!p_getc(&itemsbuf[i].usesound2,f))
35708 {
35709 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
35710 }
35711
35712 //New itemdata vars -Z
35713 //! version 27
35714
35715 if(!p_getc(&itemsbuf[i].weap_data.imitate_weapon,f))
35716 {
35717 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",49);
35718 }
35719 if(!p_getc(&itemsbuf[i].weap_data.default_defense,f))
35720 {
35721 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",50);
35722 }
35723 if(!p_igetl(&itemsbuf[i].weaprange,f))
35724 {
35725 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",51);
35726 }
35727 if(!p_igetl(&itemsbuf[i].weapduration,f))
35728 {
35729 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",52);
35730 }
35731 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
35732 if(!p_igetl(&itemsbuf[i].weap_pattern[q],f))
35733 {
35734 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",53);
35735 }
35736 }
35737 //version 28
35738 if(!p_igetl(&itemsbuf[i].duplicates,f))
35739 {
35740 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",54);
35741 }
35742 for ( int32_t q = 0; q < INITIAL_D; q++ )
35743 {
35744 if(!p_igetl(&itemsbuf[i].weap_data.initd[q],f))
35745 {
35746 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",55);
35747 }
35748 }
35749
35750 if(!p_getc(&itemsbuf[i].drawlayer,f))
35751 {
35752 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",57);
35753 }
35754
35755
35756 if(!p_igetl(&itemsbuf[i].hxofs,f))
35757 {
35758 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",58);
35759 }
35760 if(!p_igetl(&itemsbuf[i].hyofs,f))
35761 {
35762 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",59);
35763 }
35764 if(!p_igetl(&itemsbuf[i].hxsz,f))
35765 {
35766 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",60);
35767 }
35768 if(!p_igetl(&itemsbuf[i].hysz,f))
35769 {
35770 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",61);
35771 }
35772 if(!p_igetl(&itemsbuf[i].hzsz,f))
35773 {
35774 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",62);
35775 }
35776 if(!p_igetl(&itemsbuf[i].xofs,f))
35777 {
35778 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",63);
35779 }
35780 if(!p_igetl(&itemsbuf[i].yofs,f))
35781 {
35782 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",64);
35783 }
35784 if(!p_igetl(&itemsbuf[i].weap_data.hxofs,f))
35785 {
35786 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",65);
35787 }
35788 if(!p_igetl(&itemsbuf[i].weap_data.hyofs,f))
35789 {
35790 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",66);
35791 }
35792 if(!p_igetl(&itemsbuf[i].weap_data.hxsz,f))
35793 {
35794 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",67);
35795 }
35796 if(!p_igetl(&itemsbuf[i].weap_data.hysz,f))
35797 {
35798 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",68);
35799 }
35800 if(!p_igetl(&itemsbuf[i].weap_data.hzsz,f))
35801 {
35802 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",69);
35803 }
35804 if(!p_igetl(&itemsbuf[i].weap_data.xofs,f))
35805 {
35806 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",70);
35807 }
35808 if(!p_igetl(&itemsbuf[i].weap_data.yofs,f))
35809 {
35810 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",71);
35811 }
35812 if(!p_igetw(&itemsbuf[i].weap_data.script,f))
35813 {
35814 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",72);
35815 }
35816 if(!p_igetl(&itemsbuf[i].wpnsprite,f))
35817 {
35818 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",73);
35819 }
35820 if(!p_igetl(&itemsbuf[i].magiccosttimer[0],f))
35821 {
35822 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",74);
35823 }
35824 if(!p_igetl(&itemsbuf[i].overrideFLAGS,f))
35825 {
35826 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",75);
35827 }
35828 if(!p_igetl(&itemsbuf[i].tilew,f))
35829 {
35830 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",76);
35831 }
35832 if(!p_igetl(&itemsbuf[i].tileh,f))
35833 {
35834 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",77);
35835 }
35836 if(!p_igetl(&itemsbuf[i].weap_data.override_flags,f))
35837 {
35838 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",78);
35839 }
35840 if(!p_igetl(&itemsbuf[i].weap_data.tilew,f))
35841 {
35842 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",79);
35843 }
35844 if(!p_igetl(&itemsbuf[i].weap_data.tileh,f))
35845 {
35846 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",80);
35847 }
35848 if(!p_igetl(&itemsbuf[i].pickup,f))
35849 {
35850 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",81);
35851 }
35852 if(!p_igetw(&itemsbuf[i].pstring,f))
35853 {
35854 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",82);
35855 }
35856 if(!p_igetw(&itemsbuf[i].pickup_string_flags,f))
35857 {
35858 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",83);
35859 }
35860
35861 if(!p_getc(&itemsbuf[i].cost_counter[0],f))
35862 {
35863 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",84);
35864 }
35865
35866 //InitD[] labels
35867 for ( int32_t q = 0; q < 8; q++ )
35868 {
35869 for ( int32_t w = 0; w < 65; w++ )
35870 {
35871 if(!p_getc(&itemsbuf[i].initD_label[q][w],f))
35872 {
35873 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",85);
35874 }
35875 }
35876 byte dummy;
35877 for ( int32_t w = 0; w < 65; w++ )
35878 {
35879 if(!p_getc(&dummy,f))
35880 {
35881 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",86);
35882 }
35883 }
35884 for ( int32_t w = 0; w < 65; w++ )
35885 {
35886 if(!p_getc(&itemsbuf[i].sprite_initD_label[q][w],f))
35887 {
35888 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",87);
35889 }
35890 }
35891 if(!p_igetl(&itemsbuf[i].sprite_initiald[q],f))
35892 {
35893 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",88);
35894 }
35895 }
35896
35897 if(!p_igetw(&itemsbuf[i].sprite_script,f))
35898 {
35899 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",90);
35900 }
35901
35902
35903 }
35904 }
35905
35906 void FFScript::write_mapscreens(PACKFILE *f,int32_t vers_id)
35907 {
35908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
310 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
35909 {
35910
2/2
✓ Branch 0 taken 42160 times.
✓ Branch 1 taken 310 times.
42470 for(int32_t j=0; j<MAPSCRS; j++)
35911 {
35912 42160 mapscr *m = &TheMaps[i*MAPSCRS+j];
35913
35914
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->valid,f))
35915 {
35916 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35917 }
35918
35919
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->guy,f))
35920 {
35921 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35922 }
35923
35924 {
35925
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->str,f))
35926 {
35927 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35928 }
35929 }
35930
35931
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->room,f))
35932 {
35933 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35934 }
35935
35936
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->item,f))
35937 {
35938 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35939 }
35940
35941
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->hasitem, f))
35942 {
35943 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35944 }
35945
35946
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35947 {
35948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->tilewarptype[k],f))
35949 {
35950 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35951 }
35952 168640 }
35953
35954
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->door_combo_set,f))
35955 {
35956 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35957 }
35958
35959
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35960 {
35961
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->warpreturnx[k],f))
35962 {
35963 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35964 }
35965 168640 }
35966
35967
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35968 {
35969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->warpreturny[k],f))
35970 {
35971 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35972 }
35973 168640 }
35974
35975
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->warpreturnc,f))
35976 {
35977 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35978 }
35979
35980
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairx,f))
35981 {
35982 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35983 }
35984
35985
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairy,f))
35986 {
35987 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35988 }
35989
35990
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->itemx,f))
35991 {
35992 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35993 }
35994
35995
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->itemy,f))
35996 {
35997 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35998 }
35999
36000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->color,f))
36001 {
36002 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36003 }
36004
36005
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags11,f))
36006 {
36007 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36008 }
36009
36010
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36011 {
36012
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->door[k],f))
36013 {
36014 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36015 }
36016 168640 }
36017
36018
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36019 {
36020
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_iputw(m->tilewarpdmap[k],f))
36021 {
36022 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36023 }
36024 168640 }
36025
36026
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36027 {
36028
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->tilewarpscr[k],f))
36029 {
36030 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36031 }
36032 168640 }
36033
36034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->tilewarpoverlayflags,f))
36035 {
36036 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36037 }
36038
36039
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->exitdir,f))
36040 {
36041 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36042 }
36043
36044
2/2
✓ Branch 0 taken 421600 times.
✓ Branch 1 taken 42160 times.
463760 for(int32_t k=0; k<10; k++)
36045 {
36046 {
36047
1/2
✓ Branch 0 taken 421600 times.
✗ Branch 1 not taken.
421600 if(!p_iputw(m->enemy[k],f))
36048 {
36049 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36050 }
36051 }
36052 421600 }
36053
36054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->pattern,f))
36055 {
36056 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36057 }
36058
36059
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36060 {
36061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->sidewarptype[k],f))
36062 {
36063 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36064 }
36065 168640 }
36066
36067
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->sidewarpoverlayflags,f))
36068 {
36069 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36070 }
36071
36072
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivalx,f))
36073 {
36074 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36075 }
36076
36077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivaly,f))
36078 {
36079 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36080 }
36081
36082
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36083 {
36084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->path[k],f))
36085 {
36086 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36087 }
36088 168640 }
36089
36090
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36091 {
36092
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->sidewarpscr[k],f))
36093 {
36094 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36095 }
36096 168640 }
36097
36098
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36099 {
36100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_iputw(m->sidewarpdmap[k],f))
36101 {
36102 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36103 }
36104 168640 }
36105
36106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->sidewarpindex,f))
36107 {
36108 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36109 }
36110
36111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->undercombo,f))
36112 {
36113 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36114 }
36115
36116
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->undercset,f))
36117 {
36118 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36119 }
36120
36121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->catchall,f))
36122 {
36123 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36124 }
36125
36126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags,f))
36127 {
36128 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36129 }
36130
36131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags2,f))
36132 {
36133 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36134 }
36135
36136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags3,f))
36137 {
36138 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36139 }
36140
36141
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags4,f))
36142 {
36143 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36144 }
36145
36146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags5,f))
36147 {
36148 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36149 }
36150
36151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->noreset,f))
36152 {
36153 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36154 }
36155
36156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputl(m->nocarry,f))
36157 {
36158 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36159 }
36160
36161
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags6,f))
36162 {
36163 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36164 }
36165
36166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags7,f))
36167 {
36168 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36169 }
36170
36171
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags8,f))
36172 {
36173 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36174 }
36175
36176
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags9,f))
36177 {
36178 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36179 }
36180
36181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags10,f))
36182 {
36183 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36184 }
36185
36186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->csensitive,f))
36187 {
36188 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36189 }
36190
36191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->oceansfx,f))
36192 {
36193 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36194 }
36195
36196
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->bosssfx,f))
36197 {
36198 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36199 }
36200
36201
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->secretsfx,f))
36202 {
36203 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36204 }
36205
36206
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->holdupsfx,f))
36207 {
36208 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36209 }
36210
36211
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36212 {
36213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252960 times.
252960 if(!p_putc(m->layermap[k],f))
36214 {
36215 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36216 }
36217 252960 }
36218
36219
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36220 {
36221
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layerscreen[k],f))
36222 {
36223 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36224 }
36225 252960 }
36226
36227
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36228 {
36229
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layeropacity[k],f))
36230 {
36231 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36232 }
36233 252960 }
36234
36235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->timedwarptics,f))
36236 {
36237 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36238 }
36239
36240
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->nextmap,f))
36241 {
36242 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36243 }
36244
36245
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->nextscr,f))
36246 {
36247 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36248 }
36249
36250
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36251 {
36252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_iputw(m->secretcombo[k],f))
36253 {
36254 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36255 }
36256 5396480 }
36257
36258
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36259 {
36260
1/2
✓ Branch 0 taken 5396480 times.
✗ Branch 1 not taken.
5396480 if(!p_putc(m->secretcset[k],f))
36261 {
36262 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36263 }
36264 5396480 }
36265
36266
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36267 {
36268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_putc(m->secretflag[k],f))
36269 {
36270 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36271 }
36272 5396480 }
36273
36274
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36275 {
36276 try
36277 {
36278
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_iputw(m->data[k],f))
36279 {
36280 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36281 }
36282
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36283 catch(std::out_of_range& )
36284 {
36285 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36286 }
36287 7420160 }
36288
36289
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36290 {
36291 try
36292 {
36293
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->sflag[k], f))
36294 {
36295 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36296 }
36297
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36298 catch(std::out_of_range& )
36299 {
36300 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36301 }
36302 7420160 }
36303
36304
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36305 {
36306 try
36307 {
36308
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->cset[k],f))
36309 {
36310 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36311 }
36312
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36313 catch(std::out_of_range& )
36314 {
36315 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36316 }
36317 7420160 }
36318
36319
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->screen_midi,f))
36320 {
36321 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36322 }
36323
36324
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->lens_layer,f))
36325 {
36326 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36327 }
36328
36329 42160 m->ensureFFC(32);
36330
2/2
✓ Branch 0 taken 1349120 times.
✓ Branch 1 taken 42160 times.
1391280 for(int32_t k=0; k<32; k++)
36331 {
36332 1349120 ffcdata& ffc = m->ffcs[k];
36333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.data,f))
36334 {
36335 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36336 }
36337
36338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.cset,f))
36339 {
36340 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36341 }
36342
36343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.delay,f))
36344 {
36345 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36346 }
36347
36348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.x,f))
36349 {
36350 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36351 }
36352
36353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.y,f))
36354 {
36355 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36356 }
36357
36358
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vx,f))
36359 {
36360 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36361 }
36362
36363
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vy,f))
36364 {
36365 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36366 }
36367
36368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ax,f))
36369 {
36370 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36371 }
36372
36373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ay,f))
36374 {
36375 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36376 }
36377
36378
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.link,f))
36379 {
36380 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36381 }
36382
36383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_width,f))
36384 {
36385 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36386 }
36387
36388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_height,f))
36389 {
36390 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36391 }
36392
36393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.txsz,f))
36394 {
36395 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36396 }
36397
36398
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.tysz,f))
36399 {
36400 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36401 }
36402
36403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.flags,f))
36404 {
36405 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36406 }
36407
36408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.script,f))
36409 {
36410 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36411 }
36412
36413
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[0],f))
36414 {
36415 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36416 }
36417
36418
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[1],f))
36419 {
36420 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36421 }
36422
36423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[2],f))
36424 {
36425 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36426 }
36427
36428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[3],f))
36429 {
36430 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36431 }
36432
36433
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[4],f))
36434 {
36435 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36436 }
36437
36438
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[5],f))
36439 {
36440 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36441 }
36442
36443
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[6],f))
36444 {
36445 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36446 }
36447
36448
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[7],f))
36449 {
36450 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36451 }
36452
36453 1349120 }
36454
36455
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->script,f))
36456 {
36457 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36458 }
36459
2/2
✓ Branch 0 taken 337280 times.
✓ Branch 1 taken 42160 times.
379440 for ( int32_t q = 0; q < 8; q++ )
36460 {
36461
1/2
✓ Branch 0 taken 337280 times.
✗ Branch 1 not taken.
337280 if(!p_iputl(m->screeninitd[q],f))
36462 {
36463 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36464 }
36465
36466 337280 }
36467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->preloadscript,f))
36468 {
36469 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36470 }
36471
36472
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidelayers,f))
36473 {
36474 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36475 }
36476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidescriptlayers,f))
36477 {
36478 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36479 }
36480
36481
36482 42160 } //end mapscr for loop
36483 310 }
36484 }
36485 void FFScript::read_mapscreens(PACKFILE *f,int32_t vers_id)
36486 {
36487 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
36488 {
36489 for(int32_t j=0; j<MAPSCRS; j++)
36490 {
36491 mapscr *m = &TheMaps[i*MAPSCRS+j];
36492
36493 if(!p_getc(&(m->valid),f))
36494 {
36495 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36496 }
36497
36498 if(!p_getc(&(m->guy),f))
36499 {
36500 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36501 }
36502
36503 {
36504 if(!p_igetw(&(m->str),f))
36505 {
36506 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36507 }
36508 }
36509
36510 if(!p_getc(&(m->room),f))
36511 {
36512 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36513 }
36514
36515 if(!p_getc(&(m->item),f))
36516 {
36517 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36518 }
36519
36520 if(!p_getc(&(m->hasitem), f))
36521 {
36522 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36523 }
36524
36525 for(int32_t k=0; k<4; k++)
36526 {
36527 if(!p_getc(&(m->tilewarptype[k]),f))
36528 {
36529 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36530 }
36531 }
36532
36533 if(!p_igetw(&(m->door_combo_set),f))
36534 {
36535 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36536 }
36537
36538 for(int32_t k=0; k<4; k++)
36539 {
36540 if(!p_getc(&(m->warpreturnx[k]),f))
36541 {
36542 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36543 }
36544 }
36545
36546 for(int32_t k=0; k<4; k++)
36547 {
36548 if(!p_getc(&(m->warpreturny[k]),f))
36549 {
36550 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36551 }
36552 }
36553
36554 if(!p_igetw(&(m->warpreturnc),f))
36555 {
36556 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36557 }
36558
36559 if(!p_getc(&(m->stairx),f))
36560 {
36561 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36562 }
36563
36564 if(!p_getc(&(m->stairy),f))
36565 {
36566 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36567 }
36568
36569 if(!p_getc(&(m->itemx),f))
36570 {
36571 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36572 }
36573
36574 if(!p_getc(&(m->itemy),f))
36575 {
36576 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36577 }
36578
36579 if(!p_igetw(&(m->color),f))
36580 {
36581 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36582 }
36583
36584 if(!p_getc(&(m->flags11),f))
36585 {
36586 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36587 }
36588
36589 for(int32_t k=0; k<4; k++)
36590 {
36591 if(!p_getc(&(m->door[k]),f))
36592 {
36593 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36594 }
36595 }
36596
36597 for(int32_t k=0; k<4; k++)
36598 {
36599 if(!p_igetw(&(m->tilewarpdmap[k]),f))
36600 {
36601 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36602 }
36603 }
36604
36605 for(int32_t k=0; k<4; k++)
36606 {
36607 if(!p_getc(&(m->tilewarpscr[k]),f))
36608 {
36609 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36610 }
36611 }
36612
36613 if(!p_getc(&(m->tilewarpoverlayflags),f))
36614 {
36615 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36616 }
36617
36618 if(!p_getc(&(m->exitdir),f))
36619 {
36620 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36621 }
36622
36623 for(int32_t k=0; k<10; k++)
36624 {
36625 {
36626 if(!p_igetw(&(m->enemy[k]),f))
36627 {
36628 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36629 }
36630 }
36631 }
36632
36633 if(!p_getc(&(m->pattern),f))
36634 {
36635 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36636 }
36637
36638 for(int32_t k=0; k<4; k++)
36639 {
36640 if(!p_getc(&(m->sidewarptype[k]),f))
36641 {
36642 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36643 }
36644 }
36645
36646 if(!p_getc(&(m->sidewarpoverlayflags),f))
36647 {
36648 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36649 }
36650
36651 if(!p_getc(&(m->warparrivalx),f))
36652 {
36653 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36654 }
36655
36656 if(!p_getc(&(m->warparrivaly),f))
36657 {
36658 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36659 }
36660
36661 for(int32_t k=0; k<4; k++)
36662 {
36663 if(!p_getc(&(m->path[k]),f))
36664 {
36665 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36666 }
36667 }
36668
36669 for(int32_t k=0; k<4; k++)
36670 {
36671 if(!p_getc(&(m->sidewarpscr[k]),f))
36672 {
36673 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36674 }
36675 }
36676
36677 for(int32_t k=0; k<4; k++)
36678 {
36679 if(!p_igetw(&(m->sidewarpdmap[k]),f))
36680 {
36681 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36682 }
36683 }
36684
36685 if(!p_getc(&(m->sidewarpindex),f))
36686 {
36687 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36688 }
36689
36690 if(!p_igetw(&(m->undercombo),f))
36691 {
36692 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36693 }
36694
36695 if(!p_getc(&(m->undercset),f))
36696 {
36697 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36698 }
36699
36700 if(!p_igetw(&(m->catchall),f))
36701 {
36702 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36703 }
36704
36705 if(!p_getc(&(m->flags),f))
36706 {
36707 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36708 }
36709
36710 if(!p_getc(&(m->flags2),f))
36711 {
36712 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36713 }
36714
36715 if(!p_getc(&(m->flags3),f))
36716 {
36717 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36718 }
36719
36720 if(!p_getc(&(m->flags4),f))
36721 {
36722 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36723 }
36724
36725 if(!p_getc(&(m->flags5),f))
36726 {
36727 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36728 }
36729
36730 if(!p_igetw(&(m->noreset),f))
36731 {
36732 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36733 }
36734
36735 if(!p_igetl(&(m->nocarry),f))
36736 {
36737 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36738 }
36739
36740 if(!p_getc(&(m->flags6),f))
36741 {
36742 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36743 }
36744
36745 if(!p_getc(&(m->flags7),f))
36746 {
36747 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36748 }
36749
36750 if(!p_getc(&(m->flags8),f))
36751 {
36752 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36753 }
36754
36755 if(!p_getc(&(m->flags9),f))
36756 {
36757 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36758 }
36759
36760 if(!p_getc(&(m->flags10),f))
36761 {
36762 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36763 }
36764
36765 if(!p_getc(&(m->csensitive),f))
36766 {
36767 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36768 }
36769
36770 if(!p_getc(&(m->oceansfx),f))
36771 {
36772 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36773 }
36774
36775 if(!p_getc(&(m->bosssfx),f))
36776 {
36777 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36778 }
36779
36780 if(!p_getc(&(m->secretsfx),f))
36781 {
36782 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36783 }
36784
36785 if(!p_getc(&(m->holdupsfx),f))
36786 {
36787 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36788 }
36789
36790 for(int32_t k=0; k<6; k++)
36791 {
36792 if(!p_getc(&(m->layermap[k]),f))
36793 {
36794 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36795 }
36796 }
36797
36798 for(int32_t k=0; k<6; k++)
36799 {
36800 if(!p_getc(&(m->layerscreen[k]),f))
36801 {
36802 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36803 }
36804 }
36805
36806 for(int32_t k=0; k<6; k++)
36807 {
36808 if(!p_getc(&(m->layeropacity[k]),f))
36809 {
36810 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36811 }
36812 }
36813
36814 if(!p_igetw(&(m->timedwarptics),f))
36815 {
36816 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36817 }
36818
36819 if(!p_getc(&(m->nextmap),f))
36820 {
36821 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36822 }
36823
36824 if(!p_getc(&(m->nextscr),f))
36825 {
36826 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36827 }
36828
36829 for(int32_t k=0; k<128; k++)
36830 {
36831 if(!p_igetw(&(m->secretcombo[k]),f))
36832 {
36833 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36834 }
36835 }
36836
36837 for(int32_t k=0; k<128; k++)
36838 {
36839 if(!p_getc(&(m->secretcset[k]),f))
36840 {
36841 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36842 }
36843 }
36844
36845 for(int32_t k=0; k<128; k++)
36846 {
36847 if(!p_getc(&(m->secretflag[k]),f))
36848 {
36849 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36850 }
36851 }
36852
36853 for(int32_t k=0; k<176; k++)
36854 {
36855 try
36856 {
36857 if(!p_igetw(&(m->data[k]),f))
36858 {
36859 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36860 }
36861 }
36862 catch(std::out_of_range& )
36863 {
36864 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36865 }
36866 }
36867
36868 for(int32_t k=0; k<176; k++)
36869 {
36870 try
36871 {
36872 if(!p_getc(&(m->sflag[k]),f))
36873 {
36874 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36875 }
36876 }
36877 catch(std::out_of_range& )
36878 {
36879 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36880 }
36881 }
36882
36883 for(int32_t k=0; k<176; k++)
36884 {
36885 try
36886 {
36887 if(!p_getc(&(m->cset[k]),f))
36888 {
36889 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36890 }
36891 }
36892 catch(std::out_of_range& )
36893 {
36894 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36895 }
36896 }
36897
36898 if(!p_igetw(&(m->screen_midi),f))
36899 {
36900 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36901 }
36902
36903 if(!p_getc(&(m->lens_layer),f))
36904 {
36905 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36906 }
36907
36908 m->ensureFFC(32);
36909 word tempw;
36910 for(int32_t k=0; k<32; k++)
36911 {
36912 ffcdata& ffc = m->ffcs[k];
36913 if(!p_igetw(&tempw,f))
36914 {
36915 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36916 }
36917 zc_ffc_set(ffc, tempw);
36918
36919 if(!p_getc(&(ffc.cset),f))
36920 {
36921 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36922 }
36923
36924 if(!p_igetw(&(ffc.delay),f))
36925 {
36926 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36927 }
36928
36929 if(!p_igetzf(&(ffc.x),f))
36930 {
36931 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36932 }
36933
36934 if(!p_igetzf(&(ffc.y),f))
36935 {
36936 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36937 }
36938
36939 if(!p_igetzf(&(ffc.vx),f))
36940 {
36941 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36942 }
36943
36944 if(!p_igetzf(&(ffc.vy),f))
36945 {
36946 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36947 }
36948
36949 if(!p_igetzf(&(ffc.ax),f))
36950 {
36951 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36952 }
36953
36954 if(!p_igetzf(&(ffc.ay),f))
36955 {
36956 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36957 }
36958
36959 if(!p_getc(&(ffc.link),f))
36960 {
36961 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36962 }
36963
36964 if(!p_igetl(&(ffc.hit_width),f))
36965 {
36966 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36967 }
36968
36969 if(!p_igetl(&(ffc.hit_height),f))
36970 {
36971 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36972 }
36973
36974 if(!p_getc(&(ffc.txsz),f))
36975 {
36976 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36977 }
36978
36979 if(!p_getc(&(ffc.tysz),f))
36980 {
36981 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36982 }
36983
36984 if(!p_igetl(&(ffc.flags),f))
36985 {
36986 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36987 }
36988
36989 if(!p_igetw(&(ffc.script),f))
36990 {
36991 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36992 }
36993
36994 if(!p_igetl(&(ffc.initd[0]),f))
36995 {
36996 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36997 }
36998
36999 if(!p_igetl(&(ffc.initd[1]),f))
37000 {
37001 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37002 }
37003
37004 if(!p_igetl(&(ffc.initd[2]),f))
37005 {
37006 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37007 }
37008
37009 if(!p_igetl(&(ffc.initd[3]),f))
37010 {
37011 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37012 }
37013
37014 if(!p_igetl(&(ffc.initd[4]),f))
37015 {
37016 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37017 }
37018
37019 if(!p_igetl(&(ffc.initd[5]),f))
37020 {
37021 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37022 }
37023
37024 if(!p_igetl(&(ffc.initd[6]),f))
37025 {
37026 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37027 }
37028
37029 if(!p_igetl(&(ffc.initd[7]),f))
37030 {
37031 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37032 }
37033
37034 }
37035
37036 if(!p_igetw(&(m->script),f))
37037 {
37038 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37039 }
37040 for ( int32_t q = 0; q < 8; q++ )
37041 {
37042 if(!p_igetl(&(m->screeninitd[q]),f))
37043 {
37044 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37045 }
37046
37047 }
37048 if(!p_getc(&(m->preloadscript),f))
37049 {
37050 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37051 }
37052
37053 if ( vers_id >= 2 )
37054 {
37055 if(!p_getc(&(m->hidelayers),f))
37056 {
37057 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37058 }
37059 if(!p_getc(&(m->hidescriptlayers),f))
37060 {
37061 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
37062 }
37063
37064 }
37065
37066
37067 }//end mapscr all for loop
37068
37069 }
37070 }
37071 /*
37072 void FFScript::write_maps(PACKFILE *f, int32_t vers_id)
37073 {
37074 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
37075 {
37076 for(int32_t j=0; j<MAPSCRS; j++)
37077 {
37078 if ( !(FFCore.write_mapscreen(f,i,j,vers_id)) )
37079 {
37080 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODE: %d",i*j);
37081 }
37082 }
37083 }
37084 }
37085
37086 void FFScript::read_maps(PACKFILE *f, int32_t vers_id)
37087 {
37088 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
37089 {
37090 for(int32_t j=0; j<MAPSCRS; j++)
37091 {
37092 if ( !(FFCore.read_mapscreen(f,i,j,vers_id)) )
37093 {
37094 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE: %d",i*j);
37095 }
37096 }
37097 }
37098 }
37099 */
37100
37101
37102 int32_t FFScript::getHeroOTile(int32_t index1, int32_t index2)
37103 {
37104 {
37105 herospritetype lst = (herospritetype)index1;
37106 int32_t dir = index2;
37107 int32_t the_ret = 0;
37108 switch(lst)
37109 {
37110 case LSprwalkspr: the_ret = walkspr[dir][0]; break;
37111 case LSprstabspr: the_ret = stabspr[dir][0]; break;
37112 case LSprslashspr: the_ret = slashspr[dir][0]; break;
37113 case LSprrevslashspr: the_ret = revslashspr[dir][0]; break;
37114 case LSprfloatspr: the_ret = floatspr[dir][0]; break;
37115 case LSprswimspr: the_ret = swimspr[dir][0]; break;
37116 case LSprdivespr: the_ret = divespr[dir][0]; break;
37117 case LSprdrownspr: the_ret = drowningspr[dir][0]; break;
37118 case LSprsidedrownspr: the_ret = sidedrowningspr[dir][0]; break;
37119 case LSprlavadrownspr: the_ret = drowning_lavaspr[dir][0]; break;
37120 case LSprsideswimspr: the_ret = sideswimspr[dir][0]; break;
37121 case LSprsideswimslashspr: the_ret = sideswimslashspr[dir][0]; break;
37122 case LSprsideswimstabspr: the_ret = sideswimstabspr[dir][0]; break;
37123 case LSprsideswimpoundspr: the_ret = sideswimpoundspr[dir][0]; break;
37124 case LSprsideswimchargespr: the_ret = sideswimchargespr[dir][0]; break;
37125 case LSprpoundspr: the_ret = poundspr[dir][0]; break;
37126 case LSprjumpspr: the_ret = jumpspr[dir][0]; break;
37127 case LSprchargespr: the_ret = chargespr[dir][0]; break;
37128 case LSprcastingspr: the_ret = castingspr[0]; break;
37129 case LSprsideswimcastingspr: the_ret = sideswimcastingspr[0]; break;
37130 case LSprholdspr1: the_ret = holdspr[0][0][0]; break;
37131 case LSprholdspr2: the_ret = holdspr[0][1][0]; break;
37132 case LSprholdsprw1: the_ret = holdspr[1][0][0]; break;
37133 case LSprholdsprw2: the_ret = holdspr[1][1][0]; break;
37134 case LSprholdsprSw1: the_ret = sideswimholdspr[0][0]; break;
37135 case LSprholdsprSw2: the_ret = sideswimholdspr[1][0]; break;
37136 default: the_ret = 0;
37137 }
37138
37139 return the_ret*10000;
37140 }
37141 }
37142
37143 defWpnSprite FFScript::getDefWeaponSprite(int32_t wpnid)
37144 {
37145 switch(wpnid)
37146 {
37147 case wNone: return ws_0;
37148 case wSword: return ws_0;
37149 case wBeam: return wsBeam;
37150 case wBrang : return wsBrang;
37151 case wBomb: return wsBomb;
37152 case wSBomb: return wsSBomb;
37153 case wLitBomb: return wsBombblast;
37154 case wLitSBomb: return wsBombblast;
37155 case wArrow: return wsArrow;
37156 case wRefArrow: return wsArrow;
37157 case wFire: return wsFire;
37158 case wRefFire: return wsFire;
37159 case wRefFire2: return wsFire;
37160 case wWhistle: return wsUnused45;
37161 case wBait: return wsBait;
37162 case wWand: return wsWandHandle;
37163 case wMagic: return wsMagic;
37164 case wCatching: return wsUnused45;
37165 case wWind: return wsWind;
37166 case wRefMagic: return wsRefMagic;
37167 case wRefFireball: return wsRefFireball;
37168 case wRefRock: return wsRock;
37169 case wHammer: return wsHammer;
37170 case wHookshot: return wsHookshotHead;
37171 case wHSHandle: return wsHookshotHandle;
37172 case wHSChain: return wsHookshotChainH;
37173 case wSSparkle: return wsSilverSparkle;
37174 case wFSparkle: return wsGoldSparkle;
37175 case wSmack: return wsHammerSmack;
37176 case wPhantom: return wsUnused45;
37177 case wCByrna: return wsByrnaCane;
37178 case wRefBeam: return wsRefBeam;
37179 case wStomp: return wsUnused45;
37180 case lwMax: return wsUnused45;
37181 case wScript1:
37182 case wScript2:
37183 case wScript3:
37184 case wScript4:
37185 case wScript5:
37186 case wScript6:
37187 case wScript7:
37188 case wScript8:
37189 case wScript9:
37190 case wScript10: return ws_0;
37191 case wIce: return wsIce; //new
37192 case wFlame: return wsEFire2; //new
37193 //not implemented; t/b/a
37194 case wSound:
37195 case wThrown:
37196 case wPot:
37197 case wLit:
37198 case wBombos:
37199 case wEther:
37200 case wQuake:
37201 case wSword180:
37202 case wSwordLA: return wsUnused45;
37203
37204 case ewFireball: return wsFireball2;
37205 case ewArrow: return wsEArrow;
37206 case ewBrang: return wsBrang;
37207 case ewSword: return wsEBeam;
37208 case ewRock: return wsRock;
37209 case ewMagic: return wsEMagic;
37210 case ewBomb: return wsEBomb;
37211 case ewSBomb: return wsESbomb;
37212 case ewLitBomb: return wsEBombblast;
37213 case ewLitSBomb: return wsESbombblast;
37214 case ewFireTrail: return wsEFiretrail;
37215 case ewFlame: return wsEFire;
37216 case ewWind: return wsEWind;
37217 case ewFlame2: return wsEFire2;
37218 case ewFlame2Trail: return wsEFiretrail2;
37219 case ewIce: return wsIce;
37220 case ewFireball2: return wsFireball2;
37221 default: return wsUnused45;
37222 }
37223 };
37224
37225 598 void FFScript::do_loadlweapon_by_script_uid(const bool v)
37226 {
37227 598 int32_t uid = SH::get_arg(sarg1, v);
37228
1/2
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
598 if (ResolveLWeapon_checkSpriteList(uid))
37229 598 ri->lwpn = uid;
37230 else
37231 {
37232 ri->lwpn = 0;
37233 }
37234 598 }
37235
37236 void FFScript::do_loadeweapon_by_script_uid(const bool v)
37237 {
37238 int32_t uid = SH::get_arg(sarg1, v);
37239 if (ResolveEWeapon_checkSpriteList(uid))
37240 ri->ewpn = uid;
37241 else
37242 {
37243 ri->ewpn = 0;
37244 }
37245 }
37246
37247
37248 12 void FFScript::do_loadnpc_by_script_uid(const bool v)
37249 {
37250 12 int32_t uid = SH::get_arg(sarg1, v);
37251
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (ResolveSprite<enemy>(uid, "enemy"))
37252 12 ri->guyref = uid;
37253 else
37254 {
37255 ri->guyref = 0;
37256 }
37257 12 }
37258
37259 //Combo Scripts
37260
37261 99826 void FFScript::clear_combo_scripts()
37262 {
37263 99826 combo_id_cache.clear();
37264 99826 combo_id_cache.resize(region_num_rpos * 7);
37265 99826 std::fill(combo_id_cache.begin(), combo_id_cache.end(), -1);
37266 99826 FFCore.deallocateAllScriptOwnedOfType(ScriptType::Combo);
37267 99826 FFCore.clear_script_engine_data_of_type(ScriptType::Combo);
37268 99826 }
37269
37270 8236 void FFScript::clear_combo_script(const rpos_handle_t& rpos_handle)
37271 {
37272 8236 int32_t index = get_combopos_ref(rpos_handle);
37273 8236 combo_id_cache[index] = -1;
37274 8236 combopos_modified = index;
37275 8236 clear_script_engine_data(ScriptType::Combo, index);
37276 8236 }
37277
37278 3735857 int32_t FFScript::combo_script_engine(const bool preload, const bool waitdraw)
37279 {
37280 bool enabled[7];
37281
2/2
✓ Branch 0 taken 26150999 times.
✓ Branch 1 taken 3735857 times.
29886856 for (int32_t q = 0; q < 7; ++q)
37282 {
37283 26150999 enabled[q] = get_qr(qr_COMBOSCRIPTS_LAYER_0 + q);
37284 26150999 }
37285
37286 3735857 auto& combo_cache = combo_caches::script;
37287
37288 ///non-scripted effects
37289 2373234417 for_every_rpos([&](const rpos_handle_t& rpos_handle) {
37290
2/2
✓ Branch 0 taken 864990544 times.
✓ Branch 1 taken 1504508016 times.
2369498560 if (!enabled[rpos_handle.layer])
37291 1504508016 return;
37292
37293 864990544 int32_t combopos_ref = get_combopos_ref(rpos_handle);
37294 864990544 word cid = rpos_handle.data();
37295
2/2
✓ Branch 0 taken 863869279 times.
✓ Branch 1 taken 1121265 times.
864990544 if(combo_id_cache[combopos_ref] != cid)
37296 {
37297 1121265 combopos_modified = combopos_ref;
37298 1121265 combo_id_cache[combopos_ref] = cid;
37299 1121265 clear_script_engine_data(ScriptType::Combo, combopos_ref);
37300 1121265 }
37301
37302 864990544 auto script = combo_cache.minis[cid].script;
37303
2/2
✓ Branch 0 taken 856398814 times.
✓ Branch 1 taken 8591730 times.
864990544 if (script)
37304 {
37305 8591730 auto& data = get_script_engine_data(ScriptType::Combo, combopos_ref);
37306
2/2
✓ Branch 0 taken 7870889 times.
✓ Branch 1 taken 720841 times.
8591730 if (data.doscript)
37307 {
37308
4/4
✓ Branch 0 taken 356612 times.
✓ Branch 1 taken 364229 times.
✓ Branch 2 taken 352329 times.
✓ Branch 3 taken 4283 times.
720841 if (waitdraw && !data.waitdraw) return; //waitdraw not set
37309
37310 368512 ZScriptVersion::RunScript(ScriptType::Combo, script, combopos_ref);
37311
2/2
✓ Branch 0 taken 364229 times.
✓ Branch 1 taken 4283 times.
368512 if (waitdraw) data.waitdraw = true;
37312 368512 }
37313 8239401 }
37314 2369498560 });
37315
37316 3735857 return 1;
37317 }
37318
37319 792477 int32_t FFScript::Distance(double x1, double y1, double x2, double y2)
37320 {
37321 792477 double x = (x1-x2);
37322 792477 double y = (y1-y2);
37323 792477 double sum = (x*x)+(y*y);
37324 //if(((int32_t)sum) < 0)
37325 //{
37326 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37327 // return -10000;;
37328 //}
37329 792477 sum *= 1000000.0;
37330 792477 double total = sqrt(sum)*10;
37331 792477 return int32_t(total);
37332 }
37333
37334 int32_t FFScript::Distance(double x1, double y1, double x2, double y2, int32_t scale)
37335 {
37336 double x3 = x1+(x2-x1)/scale;
37337 double y3 = y1+(y2-y1)/scale;
37338 //double sum = (x*x)+(y*y);
37339 //if(((int32_t)sum) < 0)
37340 //{
37341 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37342 // return -10000;
37343 //}
37344 //sum *= 1000000.0;
37345 //double total = sqrt(sum)*10;
37346 //return int32_t(total*scale);
37347 return (FFCore.Distance(x1, y1, x3, y3)*scale);
37348 }
37349
37350 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2)
37351 {
37352 double x = (x1-x2);
37353 double y = (y1-y2);
37354 double sum = (x*x)+(y*y);
37355 //if(((int32_t)sum) < 0)
37356 //{
37357 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37358 // return -10000;;
37359 //}
37360 double total = sqrt(sum);
37361 return int32_t(total);
37362 }
37363
37364 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2, int32_t scale)
37365 {
37366 double x3 = x1+(x2-x1)/scale;
37367 double y3 = y1+(y2-y1)/scale;
37368 //double sum = (x*x)+(y*y);
37369 //if(((int32_t)sum) < 0)
37370 //{
37371 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37372 // return -10000;
37373 //}
37374 //sum *= 1000000.0;
37375 //double total = sqrt(sum)*10;
37376 //return int32_t(total*scale);
37377 return (FFCore.LongDistance(x1, y1, x3, y3)*scale);
37378 }
37379
37380 323727026 bool command_is_wait(int command)
37381 {
37382
2/2
✓ Branch 0 taken 323608039 times.
✓ Branch 1 taken 118987 times.
323727026 switch (command)
37383 {
37384 case WAITFRAME:
37385 case WAITDRAW:
37386 case WAITTO:
37387 case WAITEVENT:
37388 case WAITFRAMESR:
37389 118987 return true;
37390 }
37391 323608039 return false;
37392 323727026 }
37393
37394 220500684 bool command_is_goto(int command)
37395 {
37396 // GOTOR/return ops left out on purpose.
37397
2/2
✓ Branch 0 taken 204330811 times.
✓ Branch 1 taken 16169873 times.
220500684 switch (command)
37398 {
37399 case GOTO:
37400 case GOTOCMP:
37401 case GOTOLESS:
37402 case GOTOMORE:
37403 case GOTOTRUE:
37404 case GOTOFALSE:
37405 16169873 return true;
37406 }
37407 204330811 return false;
37408 220500684 }
37409
37410 109356253 bool command_uses_comparison_result(int command)
37411 {
37412
2/2
✓ Branch 0 taken 105165474 times.
✓ Branch 1 taken 4190779 times.
109356253 switch (command)
37413 {
37414 case GOTOTRUE:
37415 case GOTOFALSE:
37416 case GOTOMORE:
37417 case GOTOLESS:
37418 case GOTOCMP:
37419 case SETCMP:
37420 case SETTRUE:
37421 case SETTRUEI:
37422 case SETFALSE:
37423 case SETFALSEI:
37424 case SETMOREI:
37425 case SETLESSI:
37426 case SETMORE:
37427 case SETLESS:
37428 case STACKWRITEATVV_IF:
37429 4190779 return true;
37430 }
37431 105165474 return false;
37432 109356253 }
37433
37434 188446068 bool command_writes_comparison_result(int command)
37435 {
37436
2/2
✓ Branch 0 taken 180594438 times.
✓ Branch 1 taken 7851630 times.
188446068 switch (command)
37437 {
37438 case SETCMP:
37439 case SETTRUE:
37440 case SETTRUEI:
37441 case SETFALSE:
37442 case SETFALSEI:
37443 case SETMOREI:
37444 case SETLESSI:
37445 case SETMORE:
37446 case SETLESS:
37447 7851630 return true;
37448 }
37449 180594438 return false;
37450 188446068 }
37451
37452 12513333 int command_to_cmp(int command, int arg)
37453 {
37454
12/14
✓ Branch 0 taken 1692731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3125585 times.
✓ Branch 3 taken 4073 times.
✓ Branch 4 taken 65204 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3082479 times.
✓ Branch 7 taken 1406698 times.
✓ Branch 8 taken 1801841 times.
✓ Branch 9 taken 753221 times.
✓ Branch 10 taken 350759 times.
✓ Branch 11 taken 48856 times.
✓ Branch 12 taken 151201 times.
✓ Branch 13 taken 30685 times.
12513333 switch (command)
37455 {
37456 case SETCMP:
37457 case GOTOCMP:
37458 1692731 return arg;
37459
37460 case GOTOTRUE:
37461 3125585 return CMP_EQ;
37462 case GOTOFALSE:
37463 4073 return CMP_NE;
37464 case GOTOMORE:
37465 65204 return CMP_GE;
37466 case GOTOLESS:
37467 return get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LE : CMP_LT;
37468
37469 case SETTRUE:
37470 3082479 return CMP_EQ;
37471 case SETFALSE:
37472 1406698 return CMP_NE;
37473 case SETMORE:
37474 1801841 return CMP_GE;
37475 case SETLESS:
37476 753221 return CMP_LE;
37477
37478 case SETTRUEI:
37479 350759 return CMP_SETI|CMP_EQ;
37480 case SETFALSEI:
37481 48856 return CMP_SETI|CMP_NE;
37482 case SETMOREI:
37483 151201 return CMP_SETI|CMP_GE;
37484 case SETLESSI:
37485 30685 return CMP_SETI|CMP_LE;
37486 }
37487
37488 ASSERT(false);
37489 return 0;
37490 12513333 }
37491
37492 915177 bool command_could_return_not_ok(int command)
37493 {
37494
2/2
✓ Branch 0 taken 909240 times.
✓ Branch 1 taken 5937 times.
915177 switch (command)
37495 {
37496 case 0xFFFF:
37497 case EWPNDEL:
37498 case GAMECONTINUE:
37499 case GAMEEND:
37500 case GAMEEXIT:
37501 case GAMERELOAD:
37502 case GAMESAVECONTINUE:
37503 case GAMESAVEQUIT:
37504 case ITEMDEL:
37505 case LWPNDEL:
37506 case NPCKICKBUCKET:
37507 5937 return true;
37508 }
37509 909240 return false;
37510 915177 }
37511
37512 161375204 bool command_is_pure(int command)
37513 {
37514
2/2
✓ Branch 0 taken 111364586 times.
✓ Branch 1 taken 50010618 times.
161375204 switch (command)
37515 {
37516 case ABS:
37517 case ADDR:
37518 case ADDV:
37519 case ANDR:
37520 case ANDR32:
37521 case ANDV:
37522 case ANDV32:
37523 case ARCCOSR:
37524 case ARCCOSV:
37525 case ARCSINR:
37526 case ARCSINV:
37527 case BITNOT:
37528 case BITNOT32:
37529 case CASTBOOLF:
37530 case CEILING:
37531 case COMPAREV2:
37532 case COSR:
37533 case COSV:
37534 case DIVV2:
37535 case FACTORIAL:
37536 case FLOOR:
37537 case IPOWERR:
37538 case IPOWERV:
37539 case ISALLOCATEDBITMAP:
37540 case LOAD:
37541 case LOADD:
37542 case LOADI:
37543 case LOG10:
37544 case LOGE:
37545 case LSHIFTR:
37546 case LSHIFTR32:
37547 case LSHIFTV:
37548 case LSHIFTV32:
37549 case MAXR:
37550 case MAXV:
37551 case MAXVARG:
37552 case MINR:
37553 case MINV:
37554 case MINVARG:
37555 case MODR:
37556 case MODV:
37557 case MODV2:
37558 case NANDR:
37559 case NANDV:
37560 case NORR:
37561 case NORV:
37562 case NOT:
37563 case ORR:
37564 case ORR32:
37565 case ORV:
37566 case ORV32:
37567 case PEEK:
37568 case PEEKATV:
37569 case POWERR:
37570 case POWERV:
37571 case ROUND:
37572 case ROUNDAWAY:
37573 case RSHIFTR:
37574 case RSHIFTR32:
37575 case RSHIFTV:
37576 case RSHIFTV32:
37577 case SETCMP:
37578 case SETFALSE:
37579 case SETFALSEI:
37580 case SETLESS:
37581 case SETLESSI:
37582 case SETMORE:
37583 case SETMOREI:
37584 case SETR:
37585 case SETTRUE:
37586 case SETTRUEI:
37587 case SETV:
37588 case SINR:
37589 case SINV:
37590 case SUBR:
37591 case SUBV:
37592 case SUBV2:
37593 case TANR:
37594 case TANV:
37595 case TOBYTE:
37596 case TOINTEGER:
37597 case TOSHORT:
37598 case TOSIGNEDBYTE:
37599 case TOWORD:
37600 case TRUNCATE:
37601 case XNORR:
37602 case XNORV:
37603 case XORR:
37604 case XORR32:
37605 case XORV:
37606 case XORV32:
37607 50010618 return true;
37608 }
37609
37610 111364586 return false;
37611 161375204 }
37612
37613 865011134 int32_t get_combopos_ref(const rpos_handle_t& rpos_handle)
37614 {
37615 865011134 return rpos_handle.layer * region_num_rpos + (int)rpos_handle.rpos;
37616 }
37617
37618 int32_t get_combopos_ref(rpos_t rpos, int32_t layer)
37619 {
37620 return layer * region_num_rpos + (int)rpos;
37621 }
37622
37623 649434 rpos_t combopos_ref_to_rpos(int32_t combopos_ref)
37624 {
37625 649434 return (rpos_t)(combopos_ref % region_num_rpos);
37626 }
37627
37628 387550 int32_t combopos_ref_to_layer(int32_t combopos_ref)
37629 {
37630 387550 return combopos_ref / region_num_rpos;
37631 }
37632
37633 ScriptEngineData& get_ffc_script_engine_data(int index)
37634 {
37635 return get_script_engine_data(ScriptType::FFC, index);
37636 }
37637
37638 1638734 ScriptEngineData& get_item_script_engine_data(int index)
37639 {
37640 1638734 return get_script_engine_data(ScriptType::Item, index);
37641 }
37642